PHP使用SwiftMailer发送邮件
用到了swiftmailer 的lib库
require_once 'lib/swift_required.php';
//给我发送邮件
function mailer(){
$body ="要发送的内容";
$subject = "要发送主题"
$transport = Swift_SmtpTransport::newInstance('smtp.qq.com', 25);//设置发送 smtp 服务器和端口
$transport->setUsername('发送邮箱 地址 ');
$transport->setPassword('发送邮箱密码');
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance();
$message->setFrom(array( '发送邮箱地址' =>'发送人'));
$message->setTo(array('接受邮箱地址' => '接受人'));
$message->setSubject($subject);
$message->setBody($body, 'text/html', 'utf-8');
//$message->attach(Swift_Attachment::fromPath('pic.jpg', 'image/jpeg')->setFilename('rename_pic.jpg'));//发送附件
try{
$mailer->send($message);
}
catch (Swift_ConnectionException $e){
echo 'There was a problem communicating with SMTP: ' . $e->getMessage();
}
}
Swift 直接与 SMTP 服务器通讯,具有非常高的发送速度和效率。
Swiftmailer的特点:
- Send emails using SMTP, sendmail, postfix or a custom Transport implementation of your own
- Support servers that require username & password and/or encryption
- Protect from header injection attacks without stripping request data content
- Send MIME compliant HTML/multipart emails
- Use event-driven plugins to customize the library
- Handle large attachments and inline/embedded images with low memory use
PHP使用SwiftMailer发送邮件的更多相关文章
- SwiftMailer 发送邮件时 提示fsockopen() 被禁用
站点转移空间,发送邮件的SwiftMailer 类提示错误如下: Warning: fsockopen() has been disabled for security reasons in D:\1 ...
- thinkphp 整合 swiftmailer 实现邮件发送
thinkphp swiftmailer(phpmailer) 文件夹结构 图 1 swiftmailer-phpmailer 将swiftmailer整合到thinkphp中.如上图 1 我下载的版 ...
- yii2-user 一个好用的用户扩展
最近使用yii2做了一个系统,涉及到了用户登录等等,之前是自己写的一套,后来要添加邮箱验证功能.有点懒,然后看到了yii2-user这个扩展.简单说下,毕竟自己研究也不深. http://yii2-u ...
- Yii2 advance swiftmailer 不能发送邮件
我用的是Yii2高级模板,在配置好邮箱后,并编写测试,测试结果表明是发送成功的,但我的邮箱就是接受不了邮件. 经过排查发现,是由 common/config/main-local.php 文件的 'u ...
- yii2 发送邮件 yii\swiftmailer\Mailer
Yii2 中发送邮件 yii\swiftmailer\Mailer 'mailer' => [ 'class' => 'yii\swiftmailer\Mailer', 'viewPath ...
- 分享一个php邮件库——swiftmailer
最近看到一个好的php邮件库,与phpmailer作用一样,但性能比phpmailer好,尤其是在处理附件的能力上,发送邮件成功的几率也高. github地址:https://github.com/s ...
- ThinkPHP 3.2.3 使用 Swift Mailer 邮件系统发送邮件
SwiftMailer 下载地址:https://github.com/swiftmailer/swiftmailer 版本:swiftmailer-5.x 把压缩包解压到 /ThinkPHP/Lib ...
- yii2发送邮件教程
作者:白狼 出处:http://www.manks.top/article/yii2_swiftMailer本文版权归作者,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接, ...
- [moka同学笔记]YII2中发送邮件示例(转载)
原文:http://yiilib.com/topic/675/Yii2%E4%B8%AD%E5%8F%91%E9%80%81%E9%82%AE%E4%BB%B6%E7%A4%BA%E4%BE%8B { ...
随机推荐
- 加解密算法二:非对称加解密及RSA算法的实现
加密和解密使用不同的密钥的一类加密算法.这类加密算法通常有两个密钥A和B,使用密钥A加密数据得到的密文,只有密钥B可以进行解密操作(即使密钥A也无法解密):相反,使用密钥B加密数据得到的密文,只有密钥 ...
- poj 3667 Hotel (线段树)
http://poj.org/problem?id=3667 Hotel Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 94 ...
- Asynchronous socket communication
来源:http://www.codeproject.com/Articles/1608/Asynchronous-socket-communication 本地下载 Download source f ...
- jquery dom ready, jqery2.1.1实现-源码分析
本文链接http://www.cnblogs.com/Bond/p/4178311.html jquery document ready的实现其很很简,虽说简单,其很很多人还是没去关注过它的实现.我 ...
- VirtualDub - 开源视频捕捉及线性处理软件
VirtualDub是一个开放源代码的视频捕捉及线性处理软件.它由Avery Lee编写,遵循GPL协议.VirtualDub可以通过摄像头捕捉视频. 官方网站http://virtualdub.or ...
- C#中使用正则表达式提取超链接地址的集中方法(转)
一般在做爬虫或者CMS的时候经常需要提取 href链接或者是src地址.此时可以使用正则表达式轻松完成. Regex reg = new Regex(@"(?is)<a[^>]* ...
- C++的表驱动法
目的:使用表驱动法,替换复杂的if/else和switch/case语句. 说明:JS 等其他语言也都支持的. 表驱动发示例:http://blog.csdn.net/zhouyulu/article ...
- Ci框架整合smarty模板引擎
Ci框架整合smarty模板引擎 备注:下载smarty时,最好选择2.6版本,其他测试有坑,ci可以是2.2或其他 大体思路:将smarty封装成ci框架的一个类,然后重新配置一下smarty,这样 ...
- Android 图片处理方法
//压缩图片大小 public static Bitmap compressImage(Bitmap image) { ByteArrayOutputStream baos = new ByteArr ...
- JNI编程(一) —— 编写一个最简单的JNI程序
来自:http://chnic.iteye.com/blog/198745 忙了好一段时间,总算得了几天的空闲.貌似很久没更新blog了,实在罪过.其实之前一直想把JNI的相关东西整理一下的,就从今天 ...