在Yii Framework中利用PHPMailer发送邮件(2011-06-02 14:06:23)

 

标签:

it

分类: 技术共享

官方扩展链接: http://www.yiiframework.com/extension/mailer/
这个扩展配置十分方便,如果有问题的话,可以打开Debug:
  1. <?php
  2. $message = 'Hello World!';
  3. $mailer = Yii::createComponent('application.extensions.mailer.EMailer');
  4. $mailer->Host = <your smtp host>;
  5. $mailer->IsSMTP();
  6. $mailer->From = '[email protected]';
  7. $mailer->AddReplyTo('[email protected]');
  8. $mailer->AddAddress('[email protected]');
  9. $mailer->FromName = 'Wei Yard';
  10. $mailer->SMTPDebug = true;//设置SMTPDebug为true,就可以打开Debug功能,根据提示去修改配置
  11. $mailer->CharSet = 'UTF-8';
  12. $mailer->Subject = Yii::t('demo', 'Yii rulez!');
  13. $mailer->Body = $message;
  14. $mailer->Send();
因为我使用163邮箱作为发件地址,这个邮件服务是需要验证功能的。必须输入 用户名和密码才能发送成功!
  1. <?php
  2. $message = 'Hello World!';
  3. $mailer = Yii::createComponent('application.extensions.mailer.EMailer');
  4. $mailer->Host = 'smtp.163.com';
  5. $mailer->IsSMTP();
  6. $mailer->SMTPAuth = true;
  7. $mailer->From = '[email protected]';
  8. $mailer->AddReplyTo('[email protected]');
  9. $mailer->AddAddress('[email protected]');
  10. $mailer->FromName = myName';
  11. $mailer->Username = 'username';  //这里输入发件地址的用户名
  12. $mailer->Password = 'password';  //这里输入发件地址的密码
  13. $mailer->SMTPDebug = true;//设置SMTPDebug为true,就可以打开Debug功能,根据提示去修改配置
  14. $mailer->CharSet = 'UTF-8';
  15. $mailer->Subject = Yii::t('demo', 'Yii rulez!');
  16. $mailer->Body = $message;
  17. $mailer->Send();
如果大家使用的服务器没有安装邮件服务器的话,我们可以使用这种方法去发送邮件!

你可能感兴趣的:(framework)