0

0

yii框架中关于邮箱封装的示例代码分享

黄舟

黄舟

发布时间:2017-07-27 15:00:50

|

1841人浏览过

|

来源于php中文网

原创

yii框架中关于邮箱封装的示例代码分享

B12
B12

B12是一个由AI驱动的一体化网站建设平台

下载
 'Swift_SmtpTransport',
                'host' => 'smtp.163.com',
                'username' => 'xxx@163.com',
                'password' => 'xxx',
                'port' => '994',
                'encryption' => 'ssl', //ssl tls
            ];

            self::$obj = \Yii::createObject([
                    'class' => 'yii\swiftmailer\Mailer',
                    'viewPath' => '@common/mail',
                    'useFileTransport' => false,
                    'transport' => self::$config,
            ]);
        }

        return self::$obj;
    }

    public static function send($toEmail, $subject, array $compose)
    {
        $user = \Wskm::getUser();
        
        if ($compose) {
        //同时设置2种内容,让用户的偏好自己选择
            self::getMailer()->compose(
                    //['html' => 'passwordResetToken-html', 'text' => 'passwordResetToken-text'], ['user' => $user]
                    //['html' => 'passwordResetToken-html'], ['user' => $user]
                    $compose
            );
        }else{
            self::getMailer()->setBody('My amazing body', 'text/html');

            self::getMailer()->addPart('My amazing body in plain text', 'text/plain');
        }
        //https://swiftmailer.symfony.com/docs/messages.html
        
        //addTo addCc addBcc
        //$message->setTo(['some@address.tld', 'other@address.tld']);
        //$message->setCc([
        //    'person1@example.org', 'person2@otherdomain.org' => 'Person 2 Name',
        //]);
        
        //->attach(Swift_Attachment::fromPath('my-document.pdf')->setFilename('cool.jpg'))
        
        /*
        // Create the message
        $message = new Swift_Message('My subject');

        // Set the body
        $message->setBody(
        '' .
        ' ' .
        '  Here is an image @@##@@embed(Swift_Image::fromPath('image.png')) .
           '" alt="Image" />' .
        '  Rest of message' .
        ' ' .
        '',
          'text/html' // Mark the content-type as HTML
        );
         */
        
        /*
         * 验证
            use Egulias\EmailValidator\EmailValidator;
            use Egulias\EmailValidator\Validation\RFCValidation;

            $validator = new EmailValidator();
            $validator->isValid("example@example.com", new RFCValidation());
         */
        
        /*
         *  加密
            $smimeSigner = new Swift_Signers_SMimeSigner();
            $smimeSigner->setSignCertificate('/path/to/certificate.pem', ['/path/to/private-key.pem', 'passphrase']);
            $message->attachSigner($smimeSigner);
         */
        
        /*
         * 回执
            $MESSAGE->setReadReceiptTo('你@地址。 TLD ');
         */
        
        /**
         * ->setCharset('iso-8859-2');    编码
         * ->setPriority(2);                设置优先级,1-5
         */
        
        return self::getMailer()->compose(
                    //['html' => 'passwordResetToken-html', 'text' => 'passwordResetToken-text'], ['user' => $user]
                    ['html' => 'passwordResetToken-html'], ['user' => $user]
                )
                ->setFrom([ self::$config['username'] => 'test robot'])
                ->setTo($toEmail)
                ->setSubject($subject)
                ->send();
    }

}
yii框架中关于邮箱封装的示例代码分享

相关专题

更多
vlookup函数使用大全
vlookup函数使用大全

本专题整合了vlookup函数相关 教程,阅读专题下面的文章了解更多详细内容。

26

2025.12.30

金山文档相关教程
金山文档相关教程

本专题整合了金山文档相关教程,阅读专题下面的文章了解更多详细操作。

28

2025.12.30

PS反选快捷键
PS反选快捷键

本专题整合了ps反选快捷键介绍,阅读下面的文章找到答案。

25

2025.12.30

表格中一行两行的方法
表格中一行两行的方法

本专题整合了表格中一行两行的相关教程,阅读专题下面的文章了解更多详细内容。

3

2025.12.30

cpu温度过高解决方法大全
cpu温度过高解决方法大全

本专题整合了cpu温度过高相关教程,阅读专题下面的文章了解更多详细内容。

5

2025.12.30

ASCII码介绍
ASCII码介绍

本专题整合了ASCII码相关内容,阅读专题下面的文章了解更多详细内容。

31

2025.12.30

GPS是什么
GPS是什么

本专题整合了GPS相关内容,阅读专题下面的文章了解更多详细内容。

3

2025.12.30

wifi拒绝接入
wifi拒绝接入

本专题整合了wifi拒绝接入相关教程,阅读下面的文章了解更多详细方法。

9

2025.12.30

丰网速运介绍
丰网速运介绍

本专题整合了丰网速运查询入口以及相关内容,阅读专题下面的文章了解更多内容。

3

2025.12.30

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
CSS3 教程
CSS3 教程

共18课时 | 4.1万人学习

R 教程
R 教程

共45课时 | 4.3万人学习

CSS教程
CSS教程

共754课时 | 17.2万人学习

关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号