How to send emails using Yii framework?
First use Composer to install the "yiisoft/yii2-swiftmailer" extension;
php composer require --prefer-dist yiisoft/yii2-swiftmailer
Then configure the parameters in the 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'=>'白狼栈'] ], ], ], ];
Then call the code "Yii:: $app->mailer" to obtain the mailer object;
$mail= Yii::$app->mailer->compose();
Finally set the email information.
$mail= Yii::$app->mailer->compose(); $mail->setTo('***@qq.com'); //要发送给那个人的邮箱 $mail->setSubject("邮件主题"); //邮件主题 $mail->setTextBody('测试text'); //发布纯文字文本 $mail->setHtmlBody("测试html text"); //发送的消息内容 var_dump($mail->send());
Recommended tutorial: "PHP"
The above is the detailed content of How to send emails in Yii framework?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Chinese version
Chinese version, very easy to use

SublimeText3 Linux new version
SublimeText3 Linux latest version
