
Yii框架怎么发送邮件?
首先使用Composer安装“yiisoft/yii2-swiftmailer”扩展;
php composer require --prefer-dist yiisoft/yii2-swiftmailer
然后配置mailer中参数;
return [
//....
'components' => [
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'viewPath' => '@common/mail',
// send all mails to a file by default. You have to set
// 'useFileTransport' to false and configure a transport
// for the mailer to send real emails.
'useFileTransport' => false,
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.163.com',
'username' => '***@163.com',
'password' => '******',
'port' => '25',
'encryption' => 'tls',
],
'messageConfig'=>[
'charset'=>'UTF-8',
'from'=>['***@163.com'=>'白狼栈']
],
],
],
];接着调用该代码“Yii::$app-youjiankuohaophpcnmailer”获取到mailer对象;
$mail= Yii::$app->mailer->compose();
最后设置邮件信息即可。
$mail= Yii::$app->mailer->compose();
$mail->setTo('***@qq.com'); //要发送给那个人的邮箱
$mail->setSubject("邮件主题"); //邮件主题
$mail->setTextBody('测试text'); //发布纯文字文本
$mail->setHtmlBody("测试html text"); //发送的消息内容
var_dump($mail->send());推荐教程:《PHP》
以上就是Yii框架怎么发送邮件?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号