您好,欢迎访问一九零五行业门户网

PHPMailer 发送邮件_PHP教程

刚刚出炉的自己博客文章来与大家共享下^_^,下面文章转载自我的博客:久酷博客
上篇文章php mail()方法发送邮件部分邮箱无法收到邮件问题 提到要介绍一下phpmailer这款免费开源的php 邮件程序,下面我们来看看吧,以下资料全部来自phpmailer官方网站:
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 等其他方式):
首先到http://phpmailer.worxware.com/ 下载最新版本的程序包
下载完成后,找到class.phpmailer.php 、class.smtp.php 两个类放到自己的目录下!
然后新建一个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!恭喜,邮件发送成功!;  
        }  
    } 
当然还有更多、更详细的配置方式,大家可以自由发挥!
http://www.bkjia.com/phpjc/486258.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/486258.htmltecharticle刚刚出炉的自己博客文章来与大家共享下^_^,下面文章转载自我的博客:久酷博客 上篇文章php mail()方法发送邮件部分邮箱无法收到邮件问题...
其它类似信息

推荐信息