您好,登錄后才能下訂單哦!
這篇文章主要介紹Yii如何設(shè)置郵箱發(fā)文件,文中介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們一定要看完!
1.在qq郵箱的設(shè)置中開啟POP3/SMTP服務(wù)
2.保存下授權(quán)碼
在Yii2配置文件中(common/config/main.php中components)添加郵箱組件
'mailer' => [ 'class' => 'yii\swiftmailer\Mailer', 'viewPath' => '@common/mail', // send all mails to a file by default. You have to set // 'useFileTransport' to false and configure a transport // for the mailer to send real emails. 'useFileTransport' => false, 'transport' => [ //這里如果你是qq的郵箱,可以參考qq客戶端設(shè)置后再進行配置 http://service.mail.qq.com/cgi-bin/help?subtype=1&&id=28&&no=1001256 'class' => 'Swift_SmtpTransport', 'host' => 'smtp.qq.com', // qq郵箱 'username' => '114***6@qq.com', //授權(quán)碼, 什么是授權(quán)碼, http://service.mail.qq.com/cgi-bin/help?subtype=1&&id=28&&no=1001256 'password' => '***', 'port' => '465', 'encryption' => 'ssl', ], 'messageConfig'=>[ 'charset'=>'UTF-8', 'from'=>['114***@qq.com'=>'developer'] ], ],
3.調(diào)用郵箱接口發(fā)送郵件
public function actionSendmail() { $mail = \YII::$app->mailer->compose(); $mail->setTo("***@qq.com"); $mail->setSubject("郵件測試"); $mail->setTextBody("textbody 25 ok?");//發(fā)布純文字文本 //$mail->setHtmlBody("htmlbody");//發(fā)布可以帶html標(biāo)簽的文本 if($mail->send()){ echo "success"; }else{ echo "failure"; } }
以上是“Yii如何設(shè)置郵箱發(fā)文件”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關(guān)知識,歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。