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 { ...
随机推荐
- MVC-Razor引擎布局
ViewBag.Title:标题 layout: @ViewBag.Title view: @{ViewBag.Title="标题"} @RenderBody():视图的内容直接渲 ...
- 洛谷 P1541 乌龟棋
题目背景 小明过生日的时候,爸爸送给他一副乌龟棋当作礼物. 题目描述 乌龟棋的棋盘是一行N个格子,每个格子上一个分数(非负整数).棋盘第1格是唯一的起点,第N格是终点,游戏要求玩家控制一个乌龟棋子从起 ...
- <四> jQuery 事件
$(document).ready(function) 将函数绑定到文档的就绪事件(当文档完成加载时) $(selector).click(function) 触发或将函数绑定到被选元素的点击事件 $ ...
- canvas 乒乓球
<!DOCTYPE html> <html> <head> <title>Bouncing Ball With inputs</title> ...
- iOS最新上线流程+续费 2015-7-20更新
一.程序上线前准备 确认图标是否⻬全,应⽤的icon图标 在以前图⽚片直接命名 为icon就可以了,在xcode5以后,苹果加 ⼊入了images.xcasset这个⽂文件夹,所有的 图标全都在这⾥里 ...
- css中table-layout:fixed 属性的用法
table-layout:fixed 属性的用法:如果想要一个table固定大小,里面的文字强制换行(尤其是在一长串英文文本,并且中间无空格分隔的情况下),以达到使过长的文字 不撑破表格的目的,一般是 ...
- U盘、移动硬盘提示格式化的处理
移动硬盘突然打不开了,一点击就提示要求格式化,这种问题本人亲历,现已解决,千万别格式化,千万别格式化,用系统自带磁盘恢复 CHKDSK命令即可解决此问题 方法/步骤 1.在开始菜单找到“运行”窗口,也 ...
- 解决在构造函数中使用Session,Session为null的问题
问题描述: public abstract class PageBase : System.Web.UI.Page 在PageBase中如何使用Session??? 我直接用 Session[&quo ...
- ASP.NET Application_Error错误日志写入
一个web项目开发已完成,测试也通过,但是,bug是测不完的,特别是在一个大的网络环境下.那么,我们就应该记录这些错误,然后改正.这里,我的出错管理页面是在global.asax里面的,利用里面的Ap ...
- loadrunner http协议put模式脚本编写
web_submit_data("rest", "Action=http://www.test.com/111ojhjh.do", "Method=P ...