溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Yii如何設(shè)置郵箱發(fā)文件

發(fā)布時間:2021-05-06 10:48:00 來源:億速云 閱讀:138 作者:小新 欄目:編程語言

這篇文章主要介紹Yii如何設(shè)置郵箱發(fā)文件,文中介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們一定要看完!

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

Yii如何設(shè)置郵箱發(fā)文件

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è)資訊頻道!

向AI問一下細(xì)節(jié)

免責(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)容。

yii
AI