╃巡洋艦㊣ 2011-03-11 21:59:35 13525次浏览 14条回复 7 1 0

下面介绍的是这个利用PHPMailer发送邮件的扩展: 本站扩展链接:http://www.yiichina.com/extension/2 官方扩展链接:http://www.yiiframework.com/extension/mailer

这个扩展配置十分方便,如果有问题的话,可以打开Debug:

<?php
$message = 'Hello World!';
$mailer = Yii::createComponent('application.extensions.mailer.EMailer');
$mailer->Host = <your smtp host>;
$mailer->IsSMTP();
$mailer->From = 'wei@example.com';
$mailer->AddReplyTo('wei@example.com');
$mailer->AddAddress('qiang@example.com');
$mailer->FromName = 'Wei Yard';
$mailer->SMTPDebug = true;   //设置SMTPDebug为true,就可以打开Debug功能,根据提示去修改配置
$mailer->CharSet = 'UTF-8';
$mailer->Subject = Yii::t('demo', 'Yii rulez!');
$mailer->Body = $message;
$mailer->Send();

因为我使用163邮箱作为发件地址,这个邮件服务是需要验证功能的。必须输入用户名和密码才能发送成功!

<?php
$message = 'Hello World!';
$mailer = Yii::createComponent('application.extensions.mailer.EMailer');
$mailer->Host = 'smtp.163.com';
$mailer->IsSMTP();
$mailer->SMTPAuth = true;
$mailer->From = 'from@163.com';
$mailer->AddReplyTo('from@163.com');
$mailer->AddAddress('to@qq.com');
$mailer->FromName = myName';
$mailer->Username = 'username';    //这里输入发件地址的用户名
$mailer->Password = 'password';    //这里输入发件地址的密码
$mailer->SMTPDebug = true;   //设置SMTPDebug为true,就可以打开Debug功能,根据提示去修改配置
$mailer->CharSet = 'UTF-8';
$mailer->Subject = Yii::t('demo', 'Yii rulez!');
$mailer->Body = $message;
$mailer->Send();

如果大家使用的服务器没有安装邮件服务器的话,我们可以使用这种方法去发送邮件!

觉得很赞
  • 回复于 2011-07-07 17:36 举报

    收藏了!感谢舰长的无私奉献!

  • 回复于 2011-08-13 12:19 举报

    顶一个 顶一个

  • 回复于 2011-10-31 11:23 举报

    还没弄成功:'(

  • 回复于 2011-10-31 15:07 举报

    先留下来再说.

  • 回复于 2011-11-02 08:45 举报

    感谢舰长,下下来看看!

  • 回复于 2012-02-23 11:45 举报

    好东东啊

  • 回复于 2012-02-24 09:04 举报

    gmail出现问题。。。。。。

  • 回复于 2012-02-24 15:51 举报

    这个真是个好东西啊~~~十分感谢分享

  • 回复于 2012-05-08 11:28 举报

    出现问题了,不知道哪里的问题,舰长看看哈

    SMTP -> get_lines(): $data was "" 
    SMTP -> get_lines(): $str is "220 163.com Anti-spam GT for Coremail System (163com[20111010]) " 
    SMTP -> get_lines(): $data is "220 163.com Anti-spam GT for Coremail System (163com[20111010]) " 
    SMTP -> FROM SERVER:220 163.com Anti-spam GT for Coremail System (163com[20111010]) 
    SMTP -> get_lines(): $data was "" 
    SMTP -> get_lines(): $str is "250-mail " 
    SMTP -> get_lines(): $data is "250-mail " 
    SMTP -> get_lines(): $data was "250-mail " 
    SMTP -> get_lines(): $str is "250-PIPELINING " 
    SMTP -> get_lines(): $data is "250-mail 250-PIPELINING " 
    SMTP -> get_lines(): $data was "250-mail 250-PIPELINING " 
    SMTP -> get_lines(): $str is "250-AUTH LOGIN PLAIN " 
    SMTP -> get_lines(): $data is "250-mail 250-PIPELINING 250-AUTH LOGIN PLAIN " 
    SMTP -> get_lines(): $data was "250-mail 250-PIPELINING 250-AUTH LOGIN PLAIN " 
    SMTP -> get_lines(): $str is "250-AUTH=LOGIN PLAIN " 
    SMTP -> get_lines(): $data is "250-mail 250-PIPELINING 250-AUTH LOGIN PLAIN 250-AUTH=LOGIN PLAIN " 
    SMTP -> get_lines(): $data was "250-mail 250-PIPELINING 250-AUTH LOGIN PLAIN 250-AUTH=LOGIN PLAIN " 
    SMTP -> get_lines(): $str is "250-coremail 1Uxr2xKj7kG0xkI17xGrU7I0s8FY2U3Uj8Cz28x1UUUUU7Ic2I0Y2UFd7YluUCa0xDrUUUUj " 
    SMTP -> get_lines(): $data is "250-mail 250-PIPELINING 250-AUTH LOGIN PLAIN 250-AUTH=LOGIN PLAIN 250-coremail 1Uxr2xKj7kG0xkI17xGrU7I0s8FY2U3Uj8Cz28x1UUUUU7Ic2I0Y2UFd7YluUCa0xDrUUUUj " 
    SMTP -> get_lines(): $data was "250-mail 250-PIPELINING 250-AUTH LOGIN PLAIN 250-AUTH=LOGIN PLAIN 250-coremail 1Uxr2xKj7kG0xkI17xGrU7I0s8FY2U3Uj8Cz28x1UUUUU7Ic2I0Y2UFd7YluUCa0xDrUUUUj " 
    SMTP -> get_lines(): $str is "250-STARTTLS " 
    SMTP -> get_lines(): $data is "250-mail 250-PIPELINING 250-AUTH LOGIN PLAIN 250-AUTH=LOGIN PLAIN 250-coremail 1Uxr2xKj7kG0xkI17xGrU7I0s8FY2U3Uj8Cz28x1UUUUU7Ic2I0Y2UFd7YluUCa0xDrUUUUj 250-STARTTLS " 
    SMTP -> get_lines(): $data was "250-mail 250-PIPELINING 250-AUTH LOGIN PLAIN 250-AUTH=LOGIN PLAIN 250-coremail 1Uxr2xKj7kG0xkI17xGrU7I0s8FY2U3Uj8Cz28x1UUUUU7Ic2I0Y2UFd7YluUCa0xDrUUUUj 250-STARTTLS " 
    SMTP -> get_lines(): $str is "250 8BITMIME " 
    SMTP -> get_lines(): $data is "250-mail 250-PIPELINING 250-AUTH LOGIN PLAIN 250-AUTH=LOGIN PLAIN 250-coremail 1Uxr2xKj7kG0xkI17xGrU7I0s8FY2U3Uj8Cz28x1UUUUU7Ic2I0Y2UFd7YluUCa0xDrUUUUj 250-STARTTLS 250 8BITMIME " 
    SMTP -> FROM SERVER: 250-mail 250-PIPELINING 250-AUTH LOGIN PLAIN 250-AUTH=LOGIN PLAIN 250-coremail 1Uxr2xKj7kG0xkI17xGrU7I0s8FY2U3Uj8Cz28x1UUUUU7Ic2I0Y2UFd7YluUCa0xDrUUUUj 250-STARTTLS 250 8BITMIME 
    SMTP -> get_lines(): $data was "" 
    SMTP -> get_lines(): $str is "334 dXNlcm5hbWU6 " 
    SMTP -> get_lines(): $data is "334 dXNlcm5hbWU6 " 
    SMTP -> get_lines(): $data was "" 
    SMTP -> get_lines(): $str is "334 UGFzc3dvcmQ6 " 
    SMTP -> get_lines(): $data is "334 UGFzc3dvcmQ6 " 
    SMTP -> get_lines(): $data was "" 
    SMTP -> get_lines(): $str is "235 Authentication successful " 
    SMTP -> get_lines(): $data is "235 Authentication successful " 
    SMTP -> get_lines(): $data was "" 
    SMTP -> get_lines(): $str is "554 MI:SPB UserReject 0,smtp3,DdGowEAZAlGukahPG9tZAA--.176S2 1336447406 please feedback at [url]http://feedback.mail.126.com/antispam/complain.php?user=wangqingqing1207@163.com[/url] " 
    SMTP -> get_lines(): $data is "554 MI:SPB UserReject 0,smtp3,DdGowEAZAlGukahPG9tZAA--.176S2 1336447406 please feedback at [url]http://feedback.mail.126.com/antispam/complain.php?user=wangqingqing1207@163.com[/url] " 
    SMTP -> FROM SERVER:554 MI:SPB UserReject 0,smtp3,DdGowEAZAlGukahPG9tZAA--.176S2 1336447406 please feedback at [url]http://feedback.mail.126.com/antispam/complain.php?user=wangqingqing1207@163.com[/url] 
    SMTP -> ERROR: MAIL not accepted from server: 554 MI:SPB UserReject 0,smtp3,DdGowEAZAlGukahPG9tZAA--.176S2 1336447406 please feedback at [url]http://feedback.mail.126.com/antispam/complain.php?user=wangqingqing1207@163.com[/url] 
    The following From address failed: [email]wangqingqing1207@163.com[/email]
    
  • 回复于 2012-05-28 14:43 举报

    打算试试,先顶了

  • 回复于 2012-05-28 16:31 举报

    支持下,哈哈

  • 回复于 2012-06-05 17:16 举报

    学习了 留下脚印

  • 回复于 2012-06-15 18:41 举报

    问题解决了吗?求助啊

  • 回复于 2017-05-24 11:18 举报

    有yii2的扩展么

您需要登录后才可以回复。登录 | 立即注册