PHPMailer是一個用於寄送電子郵件的PHP函數包。它提供的功能包括:
*.在發送郵時指定多個收件者,抄送地址,暗送地址和回複地址
*.支援多種郵件編碼包括:8bit,base64,binary和quoted-printable
*.支援SMTP驗證
*.支援冗餘SMTP伺服器
*.支援帶附件的郵件和Html格式的郵件
*.自訂郵件標頭
*.支援在郵件中內嵌圖片
*.調試靈活
*.經測試相容的SMTP伺服器包括:Sendmail,qmail,Postfix,Imail,Exchange等
*.可運行在任何平台之上
下面是我測試PHPMailer用的例子,使用的是新浪的SMTP伺服器。使用之前需要在新浪申請一個郵箱,並在設定裡面開通SMTP/POP3。該例子還示範了簡繁不同內碼和附件的傳送。
<?phprequire_once 'includes/phpmailer/class.phpmailer.php';$mail = new PHPMailer();$mail->CharSet ="UTF-8";$mail->IsSMTP();$mail->SMTPAuth = true;$mail->Host = "smtp.sina.com";$mail->Username = "amonest";$mail->Password = "xxxxx";$mail->SetFrom('amonest@sina.com', 'amonest');$mail->AddAddress('amonest@sina.com', 'amonest');$mail->Subject = 'Test Mail';$mail->MsgHTML('<b>Hello, 簡體,繁?!!</b>');$mail->AddAttachment("LICENSE.txt");if(!$mail->Send()) { echo "Mailer Error: " . $mail->ErrorInfo;} else { echo "Message sent!恭喜,郵件發送成功!";}