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的更多相关文章

  1. ios 设置亮度、声音;调用发短信、邮件、打电话

    一,设置亮度 [[UIScreen mainScreen] setBrightness:0.5];//0.0~1.0 二,设置声音 1,添加 MediaPlayer.framework 框架 2,在需 ...

  2. Android实例-打电话、发短信和邮件,取得手机IMEI号(XE8+小米2)

    结果: 1.不提示发短信卡住,点击没有反映,我猜想,可能是因为我用的是小米手机吧. 2.接收短信报错,我猜想可能是我改了里面的方法吧(哪位大神了解,求指教). 3.project -->opti ...

  3. .net邮件发送实例 邮件内容为网页模板

    .net邮件发送实例 邮件内容为网页模板 2009-07-03 09:31:01|  分类: .NET|字号 订阅      Encoding encoding = Encoding.GetEncod ...

  4. postfix 设置邮件头翻译,本域邮件不进行邮件头翻译,仅发送至外网的进行邮件头翻译?

    postfix 设置邮件头翻译,本域邮件不进行邮件头翻译,仅发送至外网的进行邮件头翻译? 现在设置的 smtp_generic_maps = hash:/etc/postfix/generic sen ...

  5. spring 5.x 系列第20篇 ——spring简单邮件、附件邮件、内嵌资源邮件、模板邮件发送 (代码配置方式)

    源码Gitub地址:https://github.com/heibaiying/spring-samples-for-all 一.说明 1.1 项目结构说明 邮件发送配置类为com.heibaiyin ...

  6. spring 5.x 系列第19篇 ——spring简单邮件、附件邮件、内嵌资源邮件、模板邮件发送 (xml配置方式)

    源码Gitub地址:https://github.com/heibaiying/spring-samples-for-all 一.说明 1.1 项目结构说明 邮件发送配置文件为springApplic ...

  7. 分享一个php邮件库——swiftmailer

    最近看到一个好的php邮件库,与phpmailer作用一样,但性能比phpmailer好,尤其是在处理附件的能力上,发送邮件成功的几率也高. github地址:https://github.com/s ...

  8. Python自动发邮件——smtplib和email库和yagmail库

    ''' 一.先导入smtplib模块 导入MIMEText库用来做纯文本的邮件模板 二.发邮件几个相关的参数,每个邮箱的发件服务器不一样,以163为例子百度搜索服务器是 smtp.163.com 三. ...

  9. thinkphp 整合 swiftmailer 实现邮件发送

    thinkphp swiftmailer(phpmailer) 文件夹结构 图 1 swiftmailer-phpmailer 将swiftmailer整合到thinkphp中.如上图 1 我下载的版 ...

随机推荐

  1. [ERROR] Error generating R.java from manifest

    把*.js文件用记事本打开,再保存为utf-8的编码覆盖,把build文件夹的文件删掉,启动.可以运行了.(在这之前试过把jdk的几个文件考到平台工具下的动作)

  2. 网络启动并安装Debian

    网络启动(PXEBoot)并安装Debian的官方文档在这里,不过官方文档有点冗长,我这里假设已经有一台安装好Debian,需要网络安装另一台(这台可以是虚拟机,通过ISO文件等等方式安装的).PXE ...

  3. 从分类,排序,top-k多个方面对推荐算法稳定性的评价

    介绍 论文名: "classification, ranking, and top-k stability of recommendation algorithms". 本文讲述比 ...

  4. hive中遇到的问题

    ) from t_1 where country ='China' group by (name = 'qq'); 结果图 select * from t_sz_part; 按照理解来说,应该只有一个 ...

  5. centos7.2 开发 部署 .net core

    1.centos7.2 安装 nginx官方文档:http://nginx.org/en/linux_packages.html#mainline 创建nginx.repo 文件 Pre-Built ...

  6. AliRedis性能

    引言:         如今redis凭借其高性能的优势, 以及丰富的数据结构作为cache已越来越流行, 逐步取代了memcached等cache产品, 在Twitter,新浪微博中广泛使用,阿里巴 ...

  7. Array的push与unshift方法性能比较分析

    从原理就可以知道,unshift的效率是较低的.原因是,它每添加一个元素,都要把现有元素往下移一个位置.但到底效率差异有多大呢?下面来测试一下. 测试环境的主要硬件:CPU T7100(1.8G):内 ...

  8. 写shader注意的一些报错

    1.Shader warning in 'Custom/1': Both vertex and fragment programs must be present in a CGPROGRAM. Ex ...

  9. iOS流布局UICollectionView系列七——三维中的球型布局

      摘要: 类似标签云的球状布局,也类似与魔方的3D布局 iOS流布局UICollectionView系列七——三维中的球型布局 一.引言 通过6篇的博客,从平面上最简单的规则摆放的布局,到不规则的瀑 ...

  10. Spring MVC中的模型数据处理

    一.综述 Spring MVC 提供了以下途径来输出模型数据: 1.ModelAndView 当处理方法返回值类型为 ModelAndView时, 方法体即可通过该对象添加模型数据到请求域. 2.Ma ...