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. Swift中文教程(七)--协议,扩展和泛型

    Protocols and Extensions 协议(接口)和扩展 Swift使用关键字protocol声明一个协议(接口): 类(classes),枚举(enumerations)和结构(stru ...

  2. Pentaho 免费版本下载地址列表

    Pentaho CE(Community Edition) 免费版本下载地址列表 http://sourceforge.net/projects/pentaho/files/Pentaho 插件名称  ...

  3. Android发短信

    设置应用一打开时候的背景图片 去掉相对布局时候的标题 去除标题必须在setContentView(R.layout.activity_main)之前. @Override protected void ...

  4. Cannot open channel to 3 at election address :3888 java.net.ConnectException: Connection refused (Connection refused)

    关于Linux中搭建分布式时可能遇到的问题 这个问题来自于今天安装zookeeper时踩的一个大坑,害的我花了一天时间.在搭建zookeeper的分布式时,往往要进行这样的配置: server.1=h ...

  5. Harbor配置ldap

    1.修改配置Harborp配置文件,共修改三处 1.1 auth_mode = ldap_auth 1.2 ldap_url = ldap://10.10.20.202 1.3 ldap_basedn ...

  6. ssh key 免密码登陆服务器,批量分发管理以及挂载远程目录的sshfs

    ssh key 免密码登陆服务器,批量分发管理以及挂载远程目录的sshfs 第一部分:使用ssh key 实现服务器间的免密码交互登陆 步骤1: 安装openssh-clients [root@001 ...

  7. Java -- 数字

    @.运用BigDecimal处理Double类型的算术运算的精度问题 原文:https://blog.csdn.net/j754379117/article/details/52238396 可使用 ...

  8. Tomcat startup.bat启动隐藏弹出的信息窗口

    to make tomcat to use javaw.exe instead of java.exe using some startup parameter or environment vari ...

  9. Android-BroadcastReceiver具体解释

    什么是Broadcast Broadcast即广播,在Android广播是很重要的功能.比如我们想在系统开机之后做某些事情.监控手机的电量.监控手机的网络状态等等.这些功能都须要用到广播.当然我们也能 ...

  10. 素数定理 nefu 117

    素数定理: 随着x的增长,P(x) ≍x/ln(x) ,P(x)表示(1,x)内的素数的个数. 这个定理,说明在1-x中,当x大到一定程度时,素数分布的概率为ln(x) 竟然还有一道题目. 素数个数的 ...