PHPMailer:Featured email transfer class for PHP

PHPMailer 是一个很有用的 PHP 发送邮件的类。它支持使用 smtp 服务器发送邮件,同时支持 Sendmail, qmail, Postfix, Imail, Exchange, Mercury, Courier 等邮件服务器。SMTP服务器的话还支持验证,多SMTP发送(不过不太清楚有什么用).邮件发送可以包括多个TO, CC, BCC and REPLY-TO,支持text和HTML两种邮件格式,可以自动换行,支持各种格式的附件及图片,自定义邮件头等基本的邮件功能。

由于 PHP 中只包含了一个 mail 函数,所以 PHPMailer 是对其很大的增强,相信是可以满足很多人的需求的,呵呵。其主要包括两个类文件:用于实现发送邮件功能的 class.phpmailer.php 和 smtp 实现的 class.smtp.php 。然后还有可以实现多种错误输出的文件,以及很详细的文档。软件发布遵循 LGPL 协议。

使用也很简单,看下面的例子就明白了:

  1. require(“class.phpmailer.php”);
  2. $mail = new PHPMailer();
  3. $mail->IsSMTP(); // send via SMTP
  4. $mail->Host = “smtp1.site.com;smtp2.site.com”; // SMTP servers
  5. $mail->SMTPAuth = true; // turn on SMTP authentication
  6. $mail->Username = “jswan”; // SMTP username
  7. $mail->Password = “secret”; // SMTP password
  8. $mail->From = “[email protected]”;
  9. $mail->FromName = “Mailer”;
  10. $mail->AddAddress(“[email protected]”,”Josh Adams”);
  11. $mail->AddAddress(“[email protected]”); // optional name
  12. $mail->AddReplyTo(“[email protected]”,”Information”);
  13. $mail->WordWrap = 50; // set word wrap
  14. $mail->AddAttachment(“/var/tmp/file.tar.gz”); // attachment
  15. $mail->AddAttachment(“/tmp/image.jpg”, “new.jpg”);
  16. $mail->IsHTML(true); // send as HTML
  17. $mail->Subject = “Here is the subject”;
  18. $mail->Body = “This is the <b>HTML body</b>”;
  19. $mail->AltBody = “This is the text-only body”;
  20. if(!$mail->Send())
  21. {
  22. echo “Message was not sent <p>”;
  23. echo “Mailer Error: ” . $mail->ErrorInfo;
  24. exit;
  25. }
  26. echo “Message has been sent”;

详见 PHPMailer 的主页

6 thoughts on “PHPMailer:Featured email transfer class for PHP”

  1. 您好!

    感谢您对我的个人BLOG的关注与支持!由于一些原因,我不得不将我的BLOG从博客中国迁移出来,访问与订阅地址也发生了变化,由此给您带来的麻烦,我谨表示歉意!

    以下是我的新BLOG的相关信息:

    BLOG地址:61.178.182.247/h/
    RSS订阅地址:61.178.182.247/h/blogrss2…

    再次谢谢!

    韩建斌

Leave a Reply to tsing Cancel reply

Your email address will not be published. Required fields are marked *