文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>使用phpmailer发送E-mail

使用phpmailer发送E-mail

时间:2007-06-24  来源:linxh


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 协议。
示例代码:
?php
require("class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP
$mail->Host = ""; // SMTP servers
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = ""; // SMTP username
$mail->Password = ""; // SMTP password
$mail->From = ""; //
$mail->FromName =""; //
$mail->AddAddress("");
$mail->AddAddress(""); // optional name
$mail->AddReplyTo("","");
$mail->WordWrap = 50; // set word wrap
$mail->AddAttachment(""); // attachment
$mail->AddAttachment("", "");
$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";
?>

API
1. void IsSMTP ()
Sets Mailer to send message using SMTP.
2. void AddAddress (string $address, [string $name = ""])
Adds a "To" address.
3. bool AddAttachment (string $path, [string $name = ""], [string $encoding = "base64"], [string $type = "application/octet-stream"])
Adds an attachment from a path on the filesystem.
Returns false if the file could not be found or accessed.
  • string $path:
    Path to the attachment.
    • string $name:
      Overrides the attachment name.
    • string $encoding:
      File encoding (see $Encoding).
    • string $type:
      File extension (MIME) type.

    4. void IsHTML (bool $bool)
    Sets message type to HTML.

    5. bool Send ()
    Creates message and assigns Mailer. If the message is not sent successfully then it returns false. Use the ErrorInfo variable to view description of the error.
    1.
    string $AltBody = ""  Sets the text-only body of the message. This automatically sets the email to multipart/alternative. This body can be read by mail clients that do not have HTML email capability such as mutt. Clients that can read HTML will view the normal Body.


    更详细的API文档,参见

    文件:
    phpmailer-1.73.tar.gz
    大小:
    67KB
    下载:
    下载


  • 相关阅读 更多 +
    排行榜 更多 +
    翌日波奇狗的历险记手机版下载

    翌日波奇狗的历险记手机版下载

    休闲益智 下载
    怪兽远征安卓版下载

    怪兽远征安卓版下载

    角色扮演 下载
    谷歌卫星地图免费版下载

    谷歌卫星地图免费版下载

    生活实用 下载