PHPMailer是一個用於傳送電子郵件的PHP函式包。直接用PHP就可以傳送,無需搭建複雜的Email服務。
基本介紹
介紹
內部函式
mail函式
Mail配置選項
名稱 | 默認 | 描述 | 可更改 |
SMTP | "localhost" | Windows 專用:SMTP 伺服器的 DNS 名稱或 IP 地址。 | PHP_INI_ALL |
smtp_port | "25" | Windows 專用:SMTP 連線埠號。自 PHP 4.3 起可用。 | PHP_INI_ALL |
sendmail_from | NULL | Windows 專用:規定從 PHP 傳送的郵件中使用的 "from" 地址。 | PHP_INI_ALL |
sendmail_path | NULL | Unix 系統專用:路徑(通常 /usr/sbin/sendmail 或 /usr/lib/sendmail) | PHP_INI_SYSTEM |
郵件教程
<?phprequire("phpmailer/class.phpmailer.php");function smtp_mail ( $sendto_email, $subject, $body, $extra_hdrs, $user_name) {$mail = new PHPMailer();1$mail->IsSMTP(); // send via SMTP phperz~com$mail->Host = "xx.xx.xx.xxx"; // SMTP servers$mail->SMTPAuth = true; // turn on SMTP authentication$mail->Username = "yourmail"; // SMTP username 注意:普通郵件認證不需要加 @域名$mail->Password = "mailPassword"; // SMTP password$mail->From = "你的郵件地址";?>
傳送示例代碼
<html><body><h3>phpmailer Unit Test</h3>請你輸入<font color="#FF6666">收信</font>的信箱地址:<form name="phpmailer" action="send.php" method="post"><input type="hidden" name="submitted" value="1"/>信箱地址: <input type="text" size="50" name="address" /><br/><input type="submit" value="傳送"/></form></body></html>
<?phprequire("class.phpmailer.php"); //下載的檔案必須放在該檔案所在目錄$mail = new PHPMailer(); //建立郵件傳送類$address = $_POST['address'];$mail->IsSMTP(); // 使用SMTP方式傳送$mail->CharSet='UTF-8';// 設定郵件的字元編碼$mail->Host = "mail.xxxxx.***"; // 您的企業郵局域名$mail->SMTPAuth = true; // 啟用SMTP驗證功能$mail->Port = "***"; //SMTP連線埠$mail->Username = ***@xxxx.***; // 郵局用戶名(請填寫完整的email地址)$mail->Password = "******"; // 郵局密碼$mail->From = ***@xxxx.***; //郵件傳送者email地址$mail->FromName = "您的名稱";$mail->AddAddress("$address", "");//收件人地址,可以替換成任何想要接收郵件的email信箱,格式是AddAddress("收件人email","收件人姓名")//$mail->AddReplyTo("", "");//$mail->AddAttachment("/var/tmp/file.tar.gz"); // 添加附屬檔案//$mail->IsHTML(true); // set email format to HTML //是否使用HTML格式$mail->Subject = "PHPMailer測試郵件"; //郵件標題$mail->Body = "Hello,這是測試郵件"; //郵件內容$mail->AltBody = "This is the body in plain text for non-HTML mail clients"; //附加信息,可以省略if(!$mail->Send()){echo "郵件傳送失敗. <p>";echo "錯誤原因: " . $mail->ErrorInfo;exit;}echo "郵件傳送成功";?>
群1發示例代碼
require("class.phpmailer.php");$mail = new PHPMailer();//通過數組方式存儲郵件接收者$address = array('aaaaaa','bbbbbb');//使用SMTP方式傳送郵件$mail->IsSMTP();//郵局伺服器$mail->Host = 'smtp.exmail.*';//開啟SMTP驗證$mail->SMTPAuth = true;//郵局主機中的用戶名$mail->Username = 'admin';//郵局密碼$mail->Password = '123456';//郵局連線埠,SMTP默認25連線埠$mail->Port=25;//郵件傳送者email地址$mail->From = 'xxxxxxx';//郵件來源(發件人)$mail->FromName = 'PHPMailer群1發Demo';$len = count($address);for ($i=0; $i < $len; $i++) { $mail->AddAddress($address[$i]);}$mail->Subject = $title;//郵件標題$mail->Body = $content;//郵件內容$mail->Send();