php发邮件:swiftmailer, php邮件库——swiftmailer
php发邮件:swiftmailer, php邮件库——swiftmailer
最近看到一个好的php邮件库,与phpmailer作用一样,但性能比phpmailer好,尤其是在处理附件的能力上,发送邮件成功的几率也高。
github地址:https://github.com/swiftmailer/swiftmailer.git
require_once ("lib/swift_required.php");
// 创建Transport对象,设置邮件服务器和端口号,并设置用户名和密码以供验证
$transport = Swift_SmtpTransport::newInstance('smtp.163.com', 25)
->setUsername('username@163.com')
->setPassword('password');
// 创建mailer对象
$mailer = Swift_Mailer::newInstance($transport);
// 创建message对象
$message = Swift_Message::newInstance();
// 设置邮件主题
$message->setSubject('这是一份测试邮件')
// 设置邮件内容,可以省略content-type
->setBody(
'<html>' .
' <head></head>' .
' <body>' .
' Here is an image <img src="' . // 内嵌文件
$message->embed(Swift_Image::fromPath('image.jpg')) .
'" alt="Image" />' .
' Rest of message' .
'<a href="http://www.baidu.com">百度</a>'.
' </body>' .
'</html>',
'text/html'
);
// 创建attachment对象,content-type这个参数可以省略
$attachment = Swift_Attachment::fromPath('image.jpg', 'image/jpeg')
->setFilename('cool.jpg');
// 添加附件
$message->attach($attachment);
// 用关联数组设置收件人地址,可以设置多个收件人
$message->setTo(array('to@qq.com' => 'toName'));
// 用关联数组设置发件人地址,可以设置多个发件人
$message->setFrom(array(
'from@163.com' => 'fromName',
));
// 添加抄送人
$message->setCc(array(
'Cc@qq.com' => 'Cc'
));
// 添加密送人
$message->setBcc(array(
'Bcc@qq.com' => 'Bcc'
));
// 设置邮件回执
$message->setReadReceiptTo('receipt@163.com');
// 发送邮件
$result = $mailer->send($message);
测试代码,测试例子:
$Requests = __DIR__ . '/../../../vendor/swiftmailer/swiftmailer/lib/swift_required.php';
require_once ($Requests);
//Requests::register_autoloader (); // 创建Transport对象,设置邮件服务器和端口号,并设置用户名和密码以供验证
$transport = \Swift_SmtpTransport::newInstance('smtp.exmail.qq.com', 25)
->setUsername('business@xxxx.com')
->setPassword('密码'); // 创建mailer对象
$mailer = \Swift_Mailer::newInstance($transport); // 创建message对象
$message = \Swift_Message::newInstance(); // 设置邮件主题
$message->setSubject('这是一份测试邮件')->setBody('aaaa');
//发送html文档
$message->setSubject('这是一份测试邮件')->setContent("text/html")->setBody('aaaa'); // 用关联数组设置收件人地址,可以设置多个收件人
$message->setTo(array('muyang@xxxx.com' => '姓名'));
// 用关联数组设置发件人地址,可以设置多个发件人
$message->setFrom(array( 'business@xxxxx.com' => '姓名', ));
// 发送邮件
$result = $mailer->send($message); echo "aaa"; exit;
php发邮件:swiftmailer, php邮件库——swiftmailer的更多相关文章
- ios 设置亮度、声音;调用发短信、邮件、打电话
一,设置亮度 [[UIScreen mainScreen] setBrightness:0.5];//0.0~1.0 二,设置声音 1,添加 MediaPlayer.framework 框架 2,在需 ...
- Android实例-打电话、发短信和邮件,取得手机IMEI号(XE8+小米2)
结果: 1.不提示发短信卡住,点击没有反映,我猜想,可能是因为我用的是小米手机吧. 2.接收短信报错,我猜想可能是我改了里面的方法吧(哪位大神了解,求指教). 3.project -->opti ...
- .net邮件发送实例 邮件内容为网页模板
.net邮件发送实例 邮件内容为网页模板 2009-07-03 09:31:01| 分类: .NET|字号 订阅 Encoding encoding = Encoding.GetEncod ...
- postfix 设置邮件头翻译,本域邮件不进行邮件头翻译,仅发送至外网的进行邮件头翻译?
postfix 设置邮件头翻译,本域邮件不进行邮件头翻译,仅发送至外网的进行邮件头翻译? 现在设置的 smtp_generic_maps = hash:/etc/postfix/generic sen ...
- spring 5.x 系列第20篇 ——spring简单邮件、附件邮件、内嵌资源邮件、模板邮件发送 (代码配置方式)
源码Gitub地址:https://github.com/heibaiying/spring-samples-for-all 一.说明 1.1 项目结构说明 邮件发送配置类为com.heibaiyin ...
- spring 5.x 系列第19篇 ——spring简单邮件、附件邮件、内嵌资源邮件、模板邮件发送 (xml配置方式)
源码Gitub地址:https://github.com/heibaiying/spring-samples-for-all 一.说明 1.1 项目结构说明 邮件发送配置文件为springApplic ...
- 分享一个php邮件库——swiftmailer
最近看到一个好的php邮件库,与phpmailer作用一样,但性能比phpmailer好,尤其是在处理附件的能力上,发送邮件成功的几率也高. github地址:https://github.com/s ...
- Python自动发邮件——smtplib和email库和yagmail库
''' 一.先导入smtplib模块 导入MIMEText库用来做纯文本的邮件模板 二.发邮件几个相关的参数,每个邮箱的发件服务器不一样,以163为例子百度搜索服务器是 smtp.163.com 三. ...
- thinkphp 整合 swiftmailer 实现邮件发送
thinkphp swiftmailer(phpmailer) 文件夹结构 图 1 swiftmailer-phpmailer 将swiftmailer整合到thinkphp中.如上图 1 我下载的版 ...
随机推荐
- JLink defective
下载了最新的JLink V622g,打开JLink命令行后,提示以下信息 The connected J-Link is defective,Proper operation cannot be gu ...
- Http和Socket 优劣比较 使用场景选择_转
转自:http://www.cnblogs.com/webwlsong/p/3198712.html 了解HTTP和Socket之前先对网络7层协议有个了解: 7 应用层6 表示层5 会话层 4 传输 ...
- Google Code Jam 2014 Round 1 A:Problem A Charging Chaos
Problem Shota the farmer has a problem. He has just moved into his newly built farmhouse, but it tur ...
- 将PHP 5.3.3 (cli)升级到PHP 5.6.31 (cli)
centos默认系统安装的是php5.3 [root@sz-local1 scripts]# rpm -qa |grep phpphp-pdo-5.3.3-47.el6.x86_64php-mysql ...
- Linux 服务器配置JDK
1. 查看java版本 [root@plttestap5 ~]# java -versionjava version "1.8.0_121"Java(TM) SE Runtime ...
- 【BZOJ2081】[Poi2010]Beads hash+调和级数
[BZOJ2081][Poi2010]Beads Description Zxl有一次决定制造一条项链,她以非常便宜的价格买了一长条鲜艳的珊瑚珠子,她现在也有一个机器,能把这条珠子切成很多块(子串), ...
- 为什么要对url进行encode
发现现在几乎所有的网站都对url中的汉字和特殊的字符,进行了urlencode操作,也就是: http://hi.baidu.com/%BE%B2%D0%C4%C0%CF%C8%CB/creat/bl ...
- 区分Web前端和后端(转载)
转载自:http://blog.csdn.net/rosetta/article/details/53871766 前言 做C开发将近六年,基本上没有接触过web相关的东西,原来听别人说web相关 ...
- WiX 中XML引用变量说明
WiX 安装工程中的XML 文件所引用变量说明: The WiX project supports the following project reference variables: Variabl ...
- maven编译问题-maven项目运行时找不到文件,解决方案之一
问题描述:以上信息是tomcat在启动项目的时候报的错误信息,发现没有找到配置文件,实际上配置文件在项目中是存在的,但是,在编译过程中,配置文件没有能加载到编译后的项目中.就造成了,找不到这些怕配置文 ...