① phpmailer怎麼使用
您好,看下第一個例子的代碼
require("class.phpmailer.php");//這個就是包含你下載的phpmailer類的網頁,必須
$mail = new phpmailer();//創建對象
$mail->From = "[email protected]";//給對象的屬性賦值,就是發件人的郵箱地址
$mail->FromName = "List manager";//發件人的名稱
$mail->Host = "smtp1.example.com;smtp2.example.com";//郵件主機的smtp地址
$mail->Mailer = "smtp";
//下面是郵件內容要用到的代碼
@MYSQL_CONNECT("localhost","root","password");
@mysql_select_db("my_company");
$query = "SELECT full_name, email,爌hoto燜ROM employee燱HERE爄d=$id";
$result =燖MYSQL_QUERY($query);
while ($row = mysql_fetch_array ($result))
{
// HTML body
$body = "Hello <font size=\"4\">" . $row["full_name"] . "</font>, <p>";
$body .= "<i>Your</i> personal photograph to this message.<p>";
$body .= "Sincerely, <br>";
$body .= "phpmailer List manager";
// Plain text body (for mail clients that cannot read HTML)
$text_body = "Hello " . $row["full_name"] . ", \n\n";
$text_body .= "Your personal photograph to this message.\n\n";
$text_body .= "Sincerely, \n";
$text_body .= "phpmailer List manager";
//上面就是你郵件要發送的內容,修改成自己的就可以了
$mail->Body = $body;
$mail->AltBody = $text_body;
$mail->AddAddress($row["email"], $row["full_name"]);//注意這個就是收件人,
$mail->AddStringAttachment($row["photo"], "YourPhoto.jpg");
if(!$mail->Send())//開始發送
echo "There has been a mail error sending to " . $row["email"] . "<br>";
// Clear all addresses and attachments for next loop
$mail->ClearAddresses();
$mail->ClearAttachments();
}
以上用到的屬性方法可以查看class.phpmailer.php的代碼,很容易知道是干什麼的。下的包里也應該有簡單的例子,可以看下。
用法看下面的例子,不就是一個類嘛。
Examples using phpmailer
1. Advanced Example
This demonstrates sending out multiple email messages with binary attachments from a MySQL database with multipart/alternative support.
require("class.phpmailer.php");
$mail = new phpmailer();
$mail->From = "[email protected]";
$mail->FromName = "List manager";
$mail->Host = "smtp1.example.com;smtp2.example.com";
$mail->Mailer = "smtp";
@MYSQL_CONNECT("localhost","root","password");
@mysql_select_db("my_company");
$query = "SELECT full_name, email,爌hoto燜ROM employee燱HERE爄d=$id";
$result =燖MYSQL_QUERY($query);
while ($row = mysql_fetch_array ($result))
{
// HTML body
$body = "Hello <font size=\"4\">" . $row["full_name"] . "</font>, <p>";
$body .= "<i>Your</i> personal photograph to this message.<p>";
$body .= "Sincerely, <br>";
$body .= "phpmailer List manager";
// Plain text body (for mail clients that cannot read HTML)
$text_body = "Hello " . $row["full_name"] . ", \n\n";
$text_body .= "Your personal photograph to this message.\n\n";
$text_body .= "Sincerely, \n";
$text_body .= "phpmailer List manager";
$mail->Body = $body;
$mail->AltBody = $text_body;
$mail->AddAddress($row["email"], $row["full_name"]);
$mail->AddStringAttachment($row["photo"], "YourPhoto.jpg");
if(!$mail->Send())
echo "There has been a mail error sending to " . $row["email"] . "<br>";
// Clear all addresses and attachments for next loop
$mail->ClearAddresses();
$mail->ClearAttachments();
}
2. Extending phpmailer
Extending classes with inheritance is one of the most powerful features of object-oriented programming. It allows you to make changes to the original class for your own personal use without hacking the original classes. Plus, it is very easy to do. I've provided an example:
Here's a class that extends the phpmailer class and sets the defaults for the particular site:
PHP include file: mail.inc.php
require("class.phpmailer.php");
class my_phpmailer extends phpmailer {
// Set default variables for all new objects
var $From = "[email protected]";
var $FromName = "Mailer";
var $Host = "smtp1.example.com;smtp2.example.com";
var $Mailer = "smtp"; // Alternative to IsSMTP()
var $WordWrap = 75;
// Replace the default error_handler
function error_handler($msg) {
print("My Site Error");
print("Description:");
printf("%s", $msg);
exit;
}
// Create an additional function
function do_something($something) {
// Place your new code here
}
}
Now here's a normal PHP page in the site, which will have all the defaults set above:
Normal PHP file: mail_test.php
require("mail.inc.php");
// Instantiate your new class
$mail = new my_phpmailer;
// Now you only need to add the necessary stuff
$mail->AddAddress("[email protected]", "Josh Adams");
$mail->Subject = "Here is the subject";
$mail->Body = "This is the message body";
$mail->AddAttachment("c:/temp/11-10-00.zip", "new_name.zip"); // optional name
if(!$mail->Send())
{
echo "There was an error sending the message";
exit;
}
echo "Message was sent successfully";
上面2個就是簡單的例子啊!你照著改改就是了。
② PHP郵件發送
可以的,PHP直接連接SMTP伺服器,進行登錄和發送郵件。不過不可能簡單哦,相當於編寫一個OUTLOOK的功能,不可能很簡單,可以參見這篇文章:http://www.chinaz.com/Program/PHP/041050242007.html
③ 我的phpmailer組件在本地能一切正常,但是上傳到空間後,顯示發送成功。卻收不到郵件。求救
看了每次,我的代碼給你參考下,我能發送成功的,希望有幫助,賬號密碼塗成了xxx,相信你懂得
header("Content-Type: text/html;charset=utf-8");
include 'PHPMailer/class.phpmailer.php';
$mail=new PHPMailer();
$mail->IsSMTP();
$mail->Host='smtp.163.com';
$mail->SMTPAuth=true;
$mail->Username='xxxxxx';
$mail->Password='xxxxxx';
$mail->CharSet='utf-8';
$mail->SMTPDebug=true;
$mail->From='[email protected]';
$mail->FromName='dk';
$mail->Subject='這是第一封信--xxx---程序發送';
$mail->IsHTML('true');
$mail->Body="<h1>哈哈,您好</h1>";
$mail->AddAddress('[email protected]');
if($mail->Send()){
echo "發送成功";
}
④ phpmailer在哪裡下載
http://www.oschina.net/p/phpmailer
點軟體下載
或者
http://sourceforge.net/projects/phpmailer/files/phpmailer%20for%20php5_6/PHPMailer%20v5.1/
http://sourceforge.net/projects/phpmailer/
⑤ phpmailer怎麼使用
我這里有一個寫好了的代碼,我也是一直在用的例子:網路網盤的,你自己下。 解壓後將文件夾mail裡面有個mail.php,你打開這個文件,裡面有需要配置的參數,你配置好了,就用瀏覽器訪問這個文件,然後進郵箱看看就知道有沒有郵件了。
⑥ phpmailer到底怎麼用
你看下第一個例子的代碼
require("class.phpmailer.php");//這個就是包含你下載的phpmailer類的網頁,必須
$mail = new phpmailer();//創建對象
$mail->From = "[email protected]";//給對象的屬性賦值,就是發件人的郵箱地址
$mail->FromName = "List manager";//發件人的名稱
$mail->Host = "smtp1.example.com;smtp2.example.com";//郵件主機的smtp地址
$mail->Mailer = "smtp";
//下面是郵件內容要用到的代碼
@MYSQL_CONNECT("localhost","root","password");
@mysql_select_db("my_company");
$query = "SELECT full_name, email,爌hoto燜ROM employee燱HERE爄d=$id";
$result =燖MYSQL_QUERY($query);
while ($row = mysql_fetch_array ($result))
{
// HTML body
$body = "Hello <font size=\"4\">" . $row["full_name"] . "</font>, <p>";
$body .= "<i>Your</i> personal photograph to this message.<p>";
$body .= "Sincerely, <br>";
$body .= "phpmailer List manager";
// Plain text body (for mail clients that cannot read HTML)
$text_body = "Hello " . $row["full_name"] . ", \n\n";
$text_body .= "Your personal photograph to this message.\n\n";
$text_body .= "Sincerely, \n";
$text_body .= "phpmailer List manager";
//上面就是你郵件要發送的內容,修改成自己的就可以了
$mail->Body = $body;
$mail->AltBody = $text_body;
$mail->AddAddress($row["email"], $row["full_name"]);//注意這個就是收件人,
$mail->AddStringAttachment($row["photo"], "YourPhoto.jpg");
if(!$mail->Send())//開始發送
echo "There has been a mail error sending to " . $row["email"] . "<br>";
// Clear all addresses and attachments for next loop
$mail->ClearAddresses();
$mail->ClearAttachments();
}
以上用到的屬性方法可以查看class.phpmailer.php的代碼,很容易知道是干什麼的。下的包里也應該有簡單的例子,可以看下。
用法看下面的例子,不就是一個類嘛。
Examples using phpmailer
1. Advanced Example
This demonstrates sending out multiple email messages with binary attachments from a MySQL database with multipart/alternative support.
require("class.phpmailer.php");
$mail = new phpmailer();
$mail->From = "[email protected]";
$mail->FromName = "List manager";
$mail->Host = "smtp1.example.com;smtp2.example.com";
$mail->Mailer = "smtp";
@MYSQL_CONNECT("localhost","root","password");
@mysql_select_db("my_company");
$query = "SELECT full_name, email,爌hoto燜ROM employee燱HERE爄d=$id";
$result =燖MYSQL_QUERY($query);
while ($row = mysql_fetch_array ($result))
{
// HTML body
$body = "Hello <font size=\"4\">" . $row["full_name"] . "</font>, <p>";
$body .= "<i>Your</i> personal photograph to this message.<p>";
$body .= "Sincerely, <br>";
$body .= "phpmailer List manager";
// Plain text body (for mail clients that cannot read HTML)
$text_body = "Hello " . $row["full_name"] . ", \n\n";
$text_body .= "Your personal photograph to this message.\n\n";
$text_body .= "Sincerely, \n";
$text_body .= "phpmailer List manager";
$mail->Body = $body;
$mail->AltBody = $text_body;
$mail->AddAddress($row["email"], $row["full_name"]);
$mail->AddStringAttachment($row["photo"], "YourPhoto.jpg");
if(!$mail->Send())
echo "There has been a mail error sending to " . $row["email"] . "<br>";
// Clear all addresses and attachments for next loop
$mail->ClearAddresses();
$mail->ClearAttachments();
}
2. Extending phpmailer
Extending classes with inheritance is one of the most powerful features of object-oriented programming. It allows you to make changes to the original class for your own personal use without hacking the original classes. Plus, it is very easy to do. I've provided an example:
Here's a class that extends the phpmailer class and sets the defaults for the particular site:
PHP include file: mail.inc.php
require("class.phpmailer.php");
class my_phpmailer extends phpmailer {
// Set default variables for all new objects
var $From = "[email protected]";
var $FromName = "Mailer";
var $Host = "smtp1.example.com;smtp2.example.com";
var $Mailer = "smtp"; // Alternative to IsSMTP()
var $WordWrap = 75;
// Replace the default error_handler
function error_handler($msg) {
print("My Site Error");
print("Description:");
printf("%s", $msg);
exit;
}
// Create an additional function
function do_something($something) {
// Place your new code here
}
}
Now here's a normal PHP page in the site, which will have all the defaults set above:
Normal PHP file: mail_test.php
require("mail.inc.php");
// Instantiate your new class
$mail = new my_phpmailer;
// Now you only need to add the necessary stuff
$mail->AddAddress("[email protected]", "Josh Adams");
$mail->Subject = "Here is the subject";
$mail->Body = "This is the message body";
$mail->AddAttachment("c:/temp/11-10-00.zip", "new_name.zip"); // optional name
if(!$mail->Send())
{
echo "There was an error sending the message";
exit;
}
echo "Message was sent successfully";
上面2個就是簡單的例子啊!你照著改改就是了
⑦ 怎麼利用php發送郵件求詳細教程
PHP雖然提供了mail()函數,但並不好用,而PHPMailer是一個不錯的郵件發送工具,接下來將詳細介紹,需要了解的朋友可以參考下:
本人使用wamp集成開發環境,Apache2.4.4, Mysql5.6.12 , php5.4.12.開始的時候使用mail()發送郵件,更改配置始終無法成功,了解到mail()函數使用需要sendmail程序。又下載了sendmail程序擴展包。按照網上的說法也改好了php.ini和sendmail.ini。使用foxmail 7.1創建了自己的qq郵箱賬戶,開啟了POP3/SMTP服務,更改發件伺服器為POP3,使用和收件伺服器相同的身份驗證,結果還是報錯:Warning: mail(): SMTP server response: 503 Error: need EHLO and AUTH first ! in F:\PHP\wamp\www\mail.php on line 8。以下是使用mail()函數發送郵件的php代碼:
[php] view plain
<span style="font-size:14px"><?php
$to = "[email protected]";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "[email protected]";
$headers = "From: $from";
$send=mail($to,$subject,$message,$headers);
if($send)
echo "Mail Sent";
else
echo "Sorry,mail sent failed!"
?></span>
在CSDN論壇上發現phpmailer可以方便快捷的發送郵件,以下寫出詳細使用教程:
1.需要下載PHPMailer文件包,(點擊打開鏈接)
2.確認你的伺服器已經系統支持socket,通過phpinfo()查看是否支持socket;
3.把文件解壓到你的WEB伺服器目錄下,就可以使用PHPMailer發送郵件了。
以下為前台表單php代碼:
[php] view plain
<span style="font-size:14px"><html>
<body>
<h3>phpmailer Unit Test</h3>
請你輸入<font color="#FF6666">收信</font>的郵箱地址:
<form name="phpmailer" action="testemail.php" method="post">
<input type="hidden" name="submitted" value="1"/>
郵箱地址: <input type="text" size="50" name="to" />
<br/>
<input type="submit" value="發送"/>
</form>
</body>
</html> </span>
以下為後台程序:
[php] view plain
<?php
/**
* Simple example script using PHPMailer with exceptions enabled
* @package phpmailer
* @version $Id$
*/
header("content-type:text/html;charset=utf-8");
ini_set("magic_quotes_runtime",0);
require('class.phpmailer.php');
try {
$mail = new PHPMailer(true); //New instance, with exceptions enabled
//$body = file_get_contents('contents.html');
//$body = preg_replace('/\\\\/','', $body); //Strip backslashes
$to = $_POST['to'];
$mail->CharSet="GB2312";//設置郵件字元編碼否則郵件會亂碼
$mail->Encoding="base64";
$mail->IsSMTP(); // tell the class to use SMTP
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Port = 25; // set the SMTP server port
$mail->Host = "smtp.qq.com"; // SMTP server
$mail->Username = "[email protected]"; // SMTP server username
$mail->Password = "000000000000"; // SMTP server password
//$mail->IsSendmail(); // tell the class to use Sendmail
$mail->AddReplyTo("[email protected]","han qing");
$mail->From = "[email protected]";
$mail->FromName = "han qing";
//$to = "[email protected]";
$mail->AddAddress($to);
$mail->Subject =$mail->Subject = "=?utf-8?B?" . base64_encode("First PHPMailer Message") . "?=";
$mail->Body = "<h1>phpmailer演示</h1> 這是用PHPMAILER發的第一份郵件,從QQ郵箱發到Google郵箱.";
$mail->AddAttachment("F:/myloe.jpg");
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->WordWrap = 80; // set word wrap
//$mail->MsgHTML($body);
$mail->IsHTML(true); // send as HTML
$mail->Send();
echo 'Message has been sent.';
} catch (phpmailerException $e) {
echo $e->errorMessage();
}
?>
⑧ php mail函數到底怎麼配置
你要用mail就得用smtp服務軟體,然後配送smtp的用戶名和密碼,埠號,然後在php mail的配置文件里配置一下SMTP的地址,用戶名密碼埠號等。
⑨ 請問一下,PHP配置SMTP怎麼弄
PHPMailer的獲取:
PHPMailer項目地址:PHPMailer 使用git命令克隆到本地,或直接在該項目頁面的右下方點擊「 Download ZIP 」即可獲取到完整的PHPMailer代碼包,再到本地解壓即可。
步驟一:使我們的QQ郵箱能夠發送郵件
這里怎麼說能夠發送郵件呢?其實我們的郵箱都是可以發送郵件的,但是要實現在我們的網站中發送郵件,那就要設置一下我們的QQ郵箱了,因為此時我們的網站現在是作為一個第三方客戶端存在的。
這里怎麼說能夠發送郵件呢?其實我們的郵箱都是可以發送郵件的,但是要實現在我們的網站中發送郵件,那就要設置一下我們的QQ郵箱了,因為此時我們的網站現在是作為一個第三方客戶端存在的
由於待會我們用到的是SMTP伺服器來發送,在這里建議把前面的兩項開啟了!當你點擊開啟的時候,它會提示:
<?phprequire_once("./functions.php");$flag=sendMail('[email protected]','lsgo在線通知','恭喜你成功加入LSGO實驗室,開啟你的學習之旅吧!');if($flag){echo"發送郵件成功!";
}else{echo"發送郵件失敗!";
}?>