在Yii Framework中利用PHPMailer发送邮件 [ 技术分享 ]
下面介绍的是这个利用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();
如果大家使用的服务器没有安装邮件服务器的话,我们可以使用这种方法去发送邮件!
共 14 条回复
-
278893912qq 回复于 2011-10-31 11:23 举报
还没弄成功:'(
-
1648053976 回复于 2012-02-23 11:45 举报
好东东啊
-
power01001 回复于 2012-02-24 09:04 举报
gmail出现问题。。。。。。
-
出现问题了,不知道哪里的问题,舰长看看哈
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]
╃巡洋艦㊣ 北京
注册时间:2010-11-21
最后登录:14分钟前
在线时长:1674小时26分
最后登录:14分钟前
在线时长:1674小时26分
- 粉丝1369
- 金钱76388
- 威望845
- 积分101578