Home > php教程 > php手册 > body text

PHP:在Yii Framework中扩展使用PHPMailer发送邮件

WBOY
Release: 2016-06-06 19:41:44
Original
920 people have browsed it

首先,你得去Yii官方下载mailer扩展组件, 官方扩展链接: http://www.yiiframework.com/extension/mailer/。 由于PHPMailer是不断更新并且针对PHP不同版本也有对应的版本,你可以根据需要,可以去PHPMailer官网下载所需要的版本,然后把mailer文件夹下的php

   首先,你得去Yii官方下载mailer扩展组件,官方扩展链接:http://www.yiiframework.com/extension/mailer/。

      由于PHPMailer是不断更新并且针对PHP不同版本也有对应的版本,你可以根据需要,可以去PHPMailer官网下载所需要的版本,然后把mailer文件夹下的phpmailer文件夹中的内容替换了。


这个扩展配置十分方便,如果有问题的话,可以打开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();
?></your>
Copy after login



因为我使用163邮箱作为发件地址,这个邮件服务是需要验证功能的。必须输入用户名和密码才能发送成功!
<?php $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 = 'subject 主题';
$mailer->Body = 'body 内容';
$mailer->AddAttachment( $this->getAssertUrl().'/emailAttach/csdn-500.png', 'CSDN_500.png' );
if ($mailer->Send()) {
  echo 'send ok!';
} else {
  echo "send error!";
}
?>
Copy after login

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


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!