yii 邮箱封装
<?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();
} }
yii 邮箱封装的更多相关文章
- YII 自封装的批量修改的mysql操作类
<?php /** * Created by PhpStorm. * User: yufen * Date: 2018/8/31 * Time: 9:54 */ namespace app\ba ...
- YII Framework学习教程-YII的异常处理
异常无处不在,作为程序员,活着就是为了创造这些异常,然后修复这些异常而存在的.YII框架封装了PHP的异常,让异常处理起来更简单. 使用 YII处理错误和异常的配置方法: 你可以在入口文件中定义YII ...
- YII model模型和登陆详解
模型是 CModel 或其子类的实例.模型用于保持数据以及与其相关的业务逻辑. 模型是单独的数据对象.它可以是数据表中的一行,或者一个用户输入的表单. 数据对象的每个字段对应模型中的一个属性.每个属性 ...
- yii2 session的使用方法
yii2打开session use yii\web\Session; $session = Yii::$app->session; // check if a session is alread ...
- IntelliJ IDEA 2017版 spring-boot 2.0.5 邮件发送简单实例 (三)
一.搭建SpringBoot项目 详见此文:https://www.cnblogs.com/liuyangfirst/p/8298588.html 注意: 需要添加mail依赖的包,同时还添加了lom ...
- Yii2 session的使用方法(1)
yii2打开session use yii\web\Session; $session = Yii::$app->session; // check if a session is alread ...
- yii1 session
在 Yii框架中使用session 的笔记: 首先,在Yii框架中,你不需要像标准PHP代码那样使用session_start(),在Yii框架中,autoStart 属性缺省被设置为true,所以, ...
- 第12.6节 Python标准库其他内置模块导览
一. 文本处理服务 string模块 : 常见的字符串操作 difflib模块: 计算差异的辅助工具 textwrap模块: 文本自动换行与填充,能够格式化文本段落,以适应给定的屏幕宽度: unico ...
- yii框架中邮箱激活(数字签名)
控制器: //发送邮箱,激活账号 public function actionEmail() { $email=Yii::$app->request->get('em ...
随机推荐
- 【tomcat启动失败问题】Unable to start embedded Tomcat
启动spring boot 项目后抛出如下异常: org.springframework.context.ApplicationContextException: Unable to start em ...
- mac Robotframework执行时报错Robot Framework installation not found.
虽然已经装了,但一直报错 ,版本是3.1.1 最新版 ➜ ~ pip install robotframework DEPRECATION: Python 2.7 will reach the en ...
- postman headers 请求参数和MD5加密签名
postman 变量可以这样写:{{timestamp}} ,也可以用系统的,{{$timestamp}},这样就不用给自己赋值了,但在 pre-requestScript中是获取不到这个值的 所以我 ...
- 使用PL/SQL能查询oracle中数据,在for update 语句中一直卡住
原因:在oracle中,执行了update或者insert语句后,都会要求commit,如果不commit却强制关闭连接,oracle就会将这条提交的记录锁住.下次就不能执行增删操作. 解决:1.查询 ...
- Qt QSpinBox 和 QDoubleSpinBox
展示一个效果: QDoubleSpinBox跟QSpinBox类似,只是多了一个decimal.
- C# Unity依赖注入
简介: 控制反转:我们向IOC容器发出获取一个对象实例的一个请求,IOC容器便把这个对象实例“注入”到我们的手中,在这个过程中你不是一个控制者而是一个请求者,依赖于容器提供给你的资源,控制权落到了容器 ...
- Android -- 《 最美有物》好看的点赞效果
1,前天在鸿洋的公众号上看到一款不错的点赞效果,是仿最美有物的点赞,再加上自己最近学习状态很差,自己想着通过这个效果练手一下,果然,花了整整两天的时间,按照以前的效率的话一天就够了,哎,已经调整了一个 ...
- ASP.NET MVC案例教程(六)
ASP.NET六 一个小难题 我们继续完善“MVC公告发布系统”,这次,我们的需求是对公告发布功能添加日志记录能力,即在发布公告前,记录一次,在公告发布成功后,再记录一次.然后还要使得其具备异常处理, ...
- windows下python环境安装
虽然是windows下安装的方式,但是linux也差不多哈: 1,首先安装python 这个是菜鸟教程的安装介绍页面,其实很清晰了:http://www.runoob.com/python3/pyth ...
- maven 安装m2e 报错
Eclipse安装maven插件m2e m2e - http://m2eclipse.sonatype.org/sites/m2e m2e-extras - http://m2eclipse.sona ...