標籤:style http io ar os 使用 sp for 檔案
第一,需要下載PHPMailer檔案包phpmailer. http://phpmailer.sourceforge.net/
第二,確認你的伺服器系統已經支援socket ,通過phpinfo();查看是否支援sockets(socket 是屬於PHP擴充部分),如果顯現為“enabled”,那就是支援了。
第三,把檔案解壓到你的web伺服器目錄下,調用類就可以了.
首先包含class.phpmailer.php,然後建立對象,設定參數,調用成員函數。
1. 郵件的字元集設定, $mail->CharSet = "GB2312"; // 這裡指定字元集!在這裡我只指定為GB2312因為這樣Outlook能正常顯示郵件主題,我嘗試過設為utf-8但在Outlook下顯示亂碼。
2. 如果是發送html格式的郵件,那麼記得也指定
3. 如果你想用它來群發郵件的話,記得修改包含檔案函數,如:
require("phpmailer/class.phpmailer.php");
改為
require_once("phpmailer/class.phpmailer.php");
<?php
require("phpmailer/class.phpmailer.php");
function smtp_mail( $sendto_email, $subject, $body, $extra_hdrs, $user_name){
$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP
$mail->Host = "200.162.244.66"; // SMTP servers
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "yourmail"; // SMTP username 注意:普通郵件認證不需要加 @網域名稱
$mail->Password = "mailPassword"; // SMTP password
$mail->From = "[email protected]"; // 寄件者郵箱
$mail->FromName = "管理員"; // 寄件者
$mail->CharSet = "GB2312"; // 這裡指定字元集!
$mail->Encoding = "base64";
$mail->AddAddress($sendto_email,"username"); // 收件者郵箱和姓名
$mail->AddReplyTo("[email protected]","yourdomain.com");
//$mail->WordWrap = 50; // set word wrap 換行字數
//$mail->AddAttachment("/var/tmp/file.tar.gz"); // attachment 附件
//$mail->AddAttachment("/tmp/image.jpg", "new.jpg");
$mail->IsHTML(true); // send as HTML
// 郵件主題
$mail->Subject = $subject;
// 郵件內容
$mail->Body = "
<html><head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=GB2312">
</head>
<body>
I love php。
</body>
</html>
";
$mail->AltBody ="text/html";
if(!$mail->Send())
{
echo "郵件發送有誤 <p>";
echo "郵件錯誤資訊: " . $mail->ErrorInfo;
exit;
}
else {
echo "$user_name 郵件發送成功!<br />";
}
}
// 參數說明(發送到, 郵件主題, 郵件內容, 附加資訊, 使用者名稱)
smtp_mail("[email protected]", "歡迎使用phpmailer!", "NULL", "yourdomain.com", "username");
?>
phpmailer使用方法