yii2如何實(shí)現(xiàn)使用qq郵箱發(fā)送文件

yii2如何實(shí)現(xiàn)使用qq郵箱發(fā)送文件

具體方法如下所示:

(學(xué)習(xí)視頻分享:編程入門

1、首先在qq郵箱的設(shè)置中開啟POP3/SMTP服務(wù)

yii2如何實(shí)現(xiàn)使用qq郵箱發(fā)送文件

保存下授權(quán)碼

在Yii2配置文件中(common/config/main.php中components)添加郵箱組件

'mailer'?=>?[ ????????????'class'?=>?'yiiswiftmailerMailer', ????????????'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è)置后再進(jìn)行配置?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'] ????????????], ????????],

調(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"; ????????} ????}

相關(guān)推薦:編程入門

以上就是yii2如何實(shí)現(xiàn)使用qq

? 版權(quán)聲明
THE END
喜歡就支持一下吧
點(diǎn)贊10 分享