Yii2.0 comes with email, yii2.0email
Most frameworks have built-in email sending classes, and yii emails are also very simple. The Code is as follows:
1. modify the configuration file. The common version is in (config/web. php ). Pro default configuration in/common/config/main-local.php 2 3 'components' => [
'Mailer' => [4 'class' => 'yii \ swiftmailer \ mailer ', 5 'usefiletransport' => false, // you must change it to false here, otherwise, the email will not send 6 'Transport '=> [7' class' => 'SWIFT _ SmtpTransport ', 8 'host' => 'smtp .163.com ', // The host configuration for each mailbox is different 9 'username' => '1970 @ 163.com ', // the sender's mailbox is 10' password' => 'xgslagfpomsxuseq ', // authorization code 11 'Port' => '25', 12' encryption '=> 'tls', 13], 14 'messageconfig' => [15 'charset' => 'utf-8 ', 16 'from' => ['2014 @ 163.com '=> 'nickname'] // sender nickname 17], 18],
], 19 20 21 the controller sends an email (custom message) 22 23 24 $ mail = Yii ::$ app-> mailer-> compose (); 25 $ mail-> setTo ('***** @ qq.com'); // recipient's email address 26 $ mail-> setSubject ("test "); // mail title 27 $ mail-> setHtmlBody ("sent content"); // sent content (HTML code can be written) 28 if ($ mail-> send () {29 echo "successful"; 30} else {31 echo "failed "; 32} 33 34 35 if the sending page is 36 37 38 $ mail = Yii: $ app-> mailer-> compose ("email "); // create an email page file in the mail folder and edit the content 39 $ mail-> setTo ('***** @ qq.com') in the file '); // recipient's email address: 40 $ mail-> setSubject ("test"); // email title: 41 if ($ mail-> send () {42 echo "successful "; 43} else {44 echo "failed"; 45}