爱生活,爱IT
全部博文(436)
分类:
2006-12-06 13:57:55
由于 PHP 中只包含了一个 mail 函数,所以 PHPMailer 是对其很大的增强,相信是可以满足很多人的需求的,呵呵。其主要包括两个类文件:用于实现发送邮件功能的 class.phpmailer.php 和 smtp 实现的 class.smtp.php 。然后还有可以实现多种错误输出的文件,以及很详细的文档。软件发布遵循 LGPL 协议。
使用也很简单,看下面的例子就明白了:
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
'
$mail->From = "";
$mail->FromName = "Mailer";
$mail->AddAddress(" Adams");
$mail->AddAddress(""); // optional name
$mail->AddReplyTo("");
$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 HTML body";
$mail->AltBody = "This is the text-only body";
if(!$mail->Send())
{
echo "Message was not sent
";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
echo "Message has been sent";
详见PHPMailer的主页:
精典收藏:SQL Server 2008 集群+SAN集成方案: