PHPMailer:Featured email transfer class for PHP
PHPMailer:Featured email transfer class for PHPPHPMailer 是一個很有用的 PHP 發(fā)送郵件的類。它支持使用 smtp 服務(wù)器發(fā)送郵件,同時支持 Sendmail, qmail, Postfix, Imail, Exchange, Mercury, Courier 等郵件服務(wù)器。SMTP服務(wù)器的話還支持驗證,多SMTP發(fā)送(不過不太清楚有什么用).郵件發(fā)送可以包括多個TO, CC, BCC and REPLY-TO,支持text和HTML兩種郵件格式,可以自動換行,支持各種格式的附件及圖片,自定義郵件頭等基本的郵件功能。
由于 PHP 中只包含了一個 mail 函數(shù),所以 PHPMailer 是對其很大的增強,相信是可以滿足很多人的需求的,呵呵。其主要包括兩個類文件:用于實現(xiàn)發(fā)送郵件功能的 class.phpmailer.php 和 smtp 實現(xiàn)的 class.smtp.php 。然后還有可以實現(xiàn)多種錯誤輸出的文件,以及很詳細的文檔。軟件發(fā)布遵循 LGPL 協(xié)議。
使用也很簡單,看下面的例子就明白了:
require('class.phpmailer.php');
$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP $mail->Host = 'smtp1.site.com;smtp2.site.com'; // SMTP servers $mail->SMTPAuth = true; // turn on SMTP authentication $mail->Username = 'jswan'; // SMTP username $mail->Password = 'secret'; // SMTP password 'www.mypchelp.cn$mail->From = '[email protected]'; $mail->FromName = 'Mailer'; $mail->AddAddress('[email protected]','Josh Adams'); $mail->AddAddress('[email protected]'); // optional name $mail->AddReplyTo('[email protected]','Information');
$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 = 'Here is the subject'; $mail->Body = 'This is the <b>HTML body</b>'; $mail->AltBody = 'This is the text-only body';
if(!$mail->Send()) { echo 'Message was not sent <p>'; echo 'Mailer Error: ' . $mail->ErrorInfo; exit; }
echo 'Message has been sent';
詳見PHPMailer的主頁:http://phpmailer.sourceforge.net/
