Heim > php教程 > php手册 > Hauptteil

PHP发送邮件(PHPMailer详细介绍及使用方法说明)

WBOY
Freigeben: 2016-06-13 10:51:27
Original
1002 Leute haben es durchsucht

PHPMailer 也是一个功能强大的邮件类

PHPMailer的主要功能特点:

    支持邮件 s/mime加密的数字签名
    支持邮件多个 TOs, CCs, BCCs and REPLY-TOs
    可以工作在任何服务器平台,所以不用担心WIN平台无法发送邮件的问题的
    支持文本/HTML格式邮件
    可以嵌入image图像
    对于邮件客户端不支持HTML阅读的进行支持
    功能强大的发送邮件调试功能debug
    自定义邮件header
    冗余SMTP服务器支持
    支持8bit, base64, binary, and quoted-printable 编码
    文字自动换行
    支持多附件发送功能
    支持SMTP服务器验证功能
    在Sendmail, qmail, Postfix, Gmail, Imail, Exchange 等平台测试成功
    提供的下载文件中,包括内容详细的说明文档及示例说明,所以不用担心难于上手的问题!
    PHPMailer 非常小巧、简单、方便、快捷

以上资料由Jiucool 翻译自phpmailer 官网,转载请注明!

PHPMailer的使用(这里以使用gmail smtp发送邮件为例,当然也支持sendmail  pop 等其他方式):

    1.首先到http://phpmailer.worxware.com/下载最新版本的程序包
    2.下载完成后,找到class.phpmailer.php 、class.smtp.php两个类放到自己的目录下!
    3.然后新建一个php文件这里命名为:phpmail_jiucool.php
    
phpmail_jiucool.php内容如下:

我直接将邮件发送模块写成一个函数postmail_jiucool_com(),大家使用的时候直接调用该函数即可,函数内容为:

function postmail_jiucool_com($to,$subject = "",$body = ""){
    //Author:Jiucool WebSite: http://www.jiucool.com
    //$to 表示收件人地址 $subject 表示邮件标题 $body表示邮件正文
    //error_reporting(E_ALL);
    error_reporting(E_STRICT);
    date_default_timezone_set("Asia/Shanghai");//设定时区东八区
    require_once('class.phpmailer.php');
    include("class.smtp.php");
    $mail             = new PHPMailer(); //new一个PHPMailer对象出来
    $body             = eregi_replace("[\]",'',$body); //对邮件内容进行必要的过滤
    $mail->CharSet ="UTF-8";//设定邮件编码,默认ISO-8859-1,如果发中文此项必须设置,否则乱码
    $mail->IsSMTP(); // 设定使用SMTP服务
    $mail->SMTPDebug  = 1;                     // 启用SMTP调试功能
                                           // 1 = errors and messages
                                           // 2 = messages only
    $mail->SMTPAuth   = true;                  // 启用 SMTP 验证功能
    $mail->SMTPSecure = "ssl";                 // 安全协议
    $mail->Host       = "smtp.googlemail.com";      // SMTP 服务器
    $mail->Port       = 465;                   // SMTP服务器的端口号
    $mail->Username   = "SMTP服务器用户名";  // SMTP服务器用户名
    $mail->Password   = "SMTP服务器密码";            // SMTP服务器密码
    $mail->SetFrom('发件人地址,如admin#jiucool.com #换成@', '发件人名称');
    $mail->AddReplyTo("邮件回复地址,如admin#jiucool.com #换成@","邮件回复人的名称");
    $mail->Subject    = $subject;
    $mail->AltBody    = "To view the message, please use an HTML compatible email viewer! - From www.jiucool.com"; // optional, comment out and test
    $mail->MsgHTML($body);
    $address = $to;
    $mail->AddAddress($address, "收件人名称");
    //$mail->AddAttachment("images/phpmailer.gif");      // attachment
    //$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
    if(!$mail->Send()) {
        echo "Mailer Error: " . $mail->ErrorInfo;
    } else {
        echo "Message sent!恭喜,邮件发送成功!";
        }
    }


当然还有更多、更详细的配置方式,大家可以自由发挥!

from: http://www.jiucool.com/phpmailer-php-email/
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Empfehlungen
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!