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!