Yii2.0 comes with email, yii2.0email

Source: Internet
Author: User

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}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.