Home > PHP Framework > YII > body text

How to use yii2 to send files using qq mailbox

王林
Release: 2021-01-25 10:18:54
forward
3488 people have browsed it

How to use yii2 to send files using qq mailbox

The specific method is as follows:

(Learning video sharing: Introduction to Programming)

1. First, log in to the qq mailbox Enable POP3/SMTP service in the settings

How to use yii2 to send files using qq mailbox

Save the authorization code

Add it in the Yii2 configuration file (common/config/main.php components) Mailbox component

'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客户端设置后再进行配置 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',
                //授权码, 什么是授权码, 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']
            ],
        ],
Copy after login

Call the mailbox interface to send emails

public function actionSendmail()
    {
        $mail = \YII::$app->mailer->compose();
        $mail->setTo("***@qq.com");
        $mail->setSubject("邮件测试");
        $mail->setTextBody("textbody 25 ok?");//发布纯文字文本
        //$mail->setHtmlBody("htmlbody");//发布可以带html标签的文本
        if($mail->send()){
            echo "success";
        }else{
            echo "failure";
        }
    }
Copy after login

Related recommendations: yii framework

The above is the detailed content of How to use yii2 to send files using qq mailbox. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!