thinkphp5使用swiftmailer
来源:互联网 发布:php仿qq聊天系统 编辑:程序博客网 时间:2024/06/06 10:01
https://github.com/swiftmailer/swiftmailer
方式1:php引入swiftmailer
(我的php安装在/usr/local/php目录下)
swiftmailer下载下来后解压,把swiftmailer-5.x/目录下的ib文件夹改名为swiftmailer,然后把swiftmailer放在centos7的/usr/local/php/lib/php目录下。
然后再thinkphp5的任意一个controller中,做如下引用:
require_once 'swiftmainler/swift_required.php';use Swift_SmtpTransport;use Swift_Mailer;use Swift_Message;use Swift_Attachment;
方式2:thinkphp5引入swiftmailer
swiftmailer下载下来后解压,把swiftmailer-5.x/目录下的ib文件夹改名为swiftmailer,然后把swiftmailer放在thinkphp5根目录下的extend目录下,然后使用Loader方法引入
thinphp5完全手册上引入自定义类库的方法-Loader
use think\Loader;Loader::import('swiftmailer.swift_required');use Swift_SmtpTransport;use Swift_Mailer;use Swift_Message;use Swift_Attachment;
然后新建一个方法如下:
public function sendMail(){ $transport = Swift_SmtpTransport::newInstance('smtp.163.com', 25); $transport->setUsername('13521146683@163.com'); $transport->setPassword('163的授权码'); $transport->setEncryption('tls'); $mailer = Swift_Mailer::newInstance($transport); $message = Swift_Message::newInstance(); $message->setFrom(array('13521146683@163.com' => 'w')); $message->setTo(array('810169879@qq.com' => 'Mr.Right', '13521146683@163.com' => 'Mr.Wrong'));//发给两个邮箱 $message->setSubject("任务反馈");//邮件标题 $message->setBody('这是一个测试', 'text/html', 'utf-8');//邮件内容// $mailer->send($message); $message->attach(Swift_Attachment::fromPath('public/test.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(); }}
其中 附件图片放在了public目录下
0 0
- thinkphp5使用swiftmailer
- Thinkphp5使用
- YII2 邮件插件SwiftMailer使用SendMail本地邮件服务器发送
- thinkphp5使用monolog
- thinkphp5下使用phinx
- thinkphp5使用bootstrap分页
- ThinkPHP5之缓存使用
- thinkPHP5.0使用phpexcel
- ThinkPHP5中使用Smarty
- ThinkPHP5使用缓存
- thinkphp5的控制台的使用
- ThinkPhp5.0的简单使用
- thinkphp5常用的使用方式
- thinkphp5 使用soap调用接口
- thinkphp5 使用GBK的方法
- thinkphp5多级控制器及其使用
- ThinkPHP5 —— 简单使用
- ThinkPhp5.0模型的使用
- 如何退出当前所有activity,重新进入loginActivity界面
- 【jdbc】oracle java tutorial—JDBC Basics
- ctype.h头文件
- python处理不合法的asccii码
- DAY24:leetcode #63 Unique Paths II
- thinkphp5使用swiftmailer
- 常见加密算法分类,用途,原理以及比较
- 搭建IE(IE8、IE9、IE10、IE11)兼容性测试环境
- 99%的人理解错 HTTP 中 GET 与 POST 的区别
- java.util.Set学习笔记
- 常用的数学运算工具类
- Java AES加密解密
- 搜索算法之零和问题
- 39个优秀的Swift UI开源库