Home >Backend Development >PHP Tutorial >Yii2 uses swiftmailer to send emails
The example in this article describes how Yii2 uses swiftmailer to send emails. Share it with everyone for your reference, the details are as follows:
'mail' => [ 'class' => 'yii\swiftmailer\Mailer', 'viewPath' => '@backend/mail', 'useFileTransport' => false,//set this property to false to send mails to real email addresses //comment the following array to send mail using php's mail function 'transport' => [ 'class' => 'Swift_SmtpTransport', 'host' => 'smtp.gmail.com', 'username' => 'username@gmail.com', 'password' => 'password', 'port' => '587', 'encryption' => 'tls', ], ], ],
Controller:
Yii::$app->mail->compose('your_view', ['params' => $params]) ->setFrom([\Yii::$app->params['supportEmail'] => 'Test Mail']) ->setTo('to_email@xx.com') ->setSubject('This is a test mail ' ) ->send();
Readers who are interested in more Yii-related content can check out the special topics of this site: "Introduction to Yii Framework and Summary of Common Techniques", " PHP Excellent Development Framework Summary", "Smarty Template Basic Tutorial", "php date and time usage summary", "php object-oriented programming introductory tutorial", "php string (string) usage summary", "php+mysql database "Introduction to Operation Tutorial" and "Summary of Common PHP Database Operation Skills"
I hope this article will be helpful to everyone's PHP programming based on the Yii framework.
The above introduces the method of Yii2 using swiftmailer to send emails, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.