Yii2 e-Mail sending problem how to solve

Source: Internet
Author: User
Tags yii
Just used the Yii mail send function, although the result returned successfully, but received the message. The configuration file code is as follows:

' Components ' and [    ' db ' = = '        class ' = ' yii\db\connection ',        ' dsn ' = ' + ' mysql:host=localhost; Dbname=yiidemo ',        ' username ' = ' root ',        ' password ' and ' root ',        ' charset ' = ' utf8 ',    ],    ' Mailer ' = = [        ' class ' = ' Yii\swiftmailer\mailer ',        ' viewPath ' = ' @common/mail ',        //Send all mails To a file by default. You has to set        //' Usefiletransport ' to false and configure a transport        ///For the mailer to send real emails.< c13/> ' usefiletransport ' = true,        ' transport ' = [             ' class ' = ' = ' swift_smtptransport ',             ' host ' = > ' smtp.qq.com ',             ' username ' = ' ******** ' @qq. com ',             ' password ' = ' ******** ',            ' port ' = ' 465 ',             ' encryption ' = ' SSL ',         ],     ],

Controller code:

Public $modelClass = ' common\models\user ';p ublic function actions () {$actions = Parent::actions ();    unset ($actions [' Update '], $actions [' Create '], $actions [' delete '], which can be written in the controller after disabling the "create" operation;    $actions [' Index '] [' preparedataprovider '] = [$this, ' Preparedataprovider ']; return $actions;} Public Function Actioncreate () {$request = Yii:: $app->request; $params = $request->post (); if ($params) {$fromName = $request->getbodyparam (' fromname '); $fromBady = $request->getbodyparam (' Frombady '); $toName = $request Getbodyparam (' ToName '); $body = $request->getbodyparam (' body '); return $this->send ($fromName, $fromBady, $ ToName, $body);} return false;} /* * Email send function * @param1 $fromName * @param1 $toName * @param1 $body * $return Boo1ean * */public function Send ($fromName, $fromBady, $toName, $body = ") {$mail = \yii:: $app->mailer->compose ()->setfrom ([$fromName = $fromBady])->setto ($toName)->sets   Ubject (' Mail send Configuration ')->settextbody ($body)Publishes plain text text->send (); if ($mail) {return [' name ' = = ' fromname ' + $fromName, ' frombady ' + $FR Ombady, ' toname ' = $toName, ' body ' and ' = ' $body,], ' message ' = = ' occurred to ['. $toName. '] E-mail Success!    ', ' code ' = 0, ' status ' = 200,]; }else{return [' name ' = ' Error ', ' message ' \ = ' occurred '. $toName. ' Message failed!    ', ' code ' = 0, ' status ' = 402,]; }}

But you'll find that the data return was successful, but you didn't get the email.

This is what you should put
'useFileTransport' => true 改成 'useFileTransport' => false,
And your email password is the QQ authorization code (to your mailbox settings---account view)

Through the above efforts you will successfully receive mail!

Related Article

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.