yii 邮箱封装
2018-06-22 05:24:35来源:未知 阅读 ()
<?php class Mailer { private static $obj; private static $config; public static function getMailer() { if (!is_object(self::$obj)) { self::$config = [ 'class' => '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 <em>amazing</em> 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( '<html>' . ' <body>' . ' Here is an image <img src="' . // Embed the file $message->embed(Swift_Image::fromPath('image.png')) . '" alt="Image" />' . ' Rest of message' . ' </body>' . '</html>', '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(); } }
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
上一篇:MySQL、PHP入门
下一篇:PHP中常见的面试题1(附答案)
- Yii操作数据库的3种方法 2020-02-20
- php验证邮箱和ip地址最简单方法 2019-12-21
- PHP类的封装与继承详解 2019-12-15
- 详解Yii2框架实现登录、退出及自动登录功能的方法 2019-12-15
- 详解PHP CURL获取邮箱地址的方法 2019-10-28
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash