yuan1994 / tp-mailer Goto Github PK
View Code? Open in Web Editor NEW一个优美的php邮件类tp-mailer,支持邮件模板、纯文本、附件邮件发送以及更多邮件功能, 邮件发送简单到只需一行代码,原生支持ThinkPHP所有框架,也非常方便其他框架扩展
License: Apache License 2.0
一个优美的php邮件类tp-mailer,支持邮件模板、纯文本、附件邮件发送以及更多邮件功能, 邮件发送简单到只需一行代码,原生支持ThinkPHP所有框架,也非常方便其他框架扩展
License: Apache License 2.0
use mailer\tp5\Mailer;
function sendEmail($to, $content) {
$subject = '测试一下'; //邮件主题
$mailer = Mailer::instance();
$mailer ->from('[email protected]', 'xxx')
->to($to)
->subject($subject)
->text($content)
->send();
}
新问题:TP 3.2.3框架下,发送附件会导致apache死机,必须重启服务器。
->attach('http://127.0.0.1/joa/测试文本.txt', '测试文本.txt')
提示 mkdir(): Invalid path
错误位置
FILE: D:\phpStudy\WWW\joa\Txp\Library\Vendor\tp-mailer\src\mailer\lib\Transport.php LINE: 120
控制器头部引用:
namespace Home\Controller;
use Think\Controller;
require_once 'Txp/Library/Vendor/tp-mailer/src/autoload.php';
use mailer\tp32\Mailer;
控制器方法部分:
$mailer = Mailer::instance();
$mailer->from('@163.com', 'WJOA邮件网关')
->to('@qq.com')
->subject('纯文本测试')
->text('欢迎您使用Tp Mailer')
->send();
}
/**
* 自动探测配置项
*/
private static function detect()
{
if (class_exists('\\think\\Config')) {
// thinkphp5自动探测初始化配置项
self::$config = \think\Config::get('mail');
} elseif (function_exists('C')) {
// thinkphp3自动探测初始化配置项
self::$config = C('mail');
} else {
// 其他框架如果未初始化则抛出异常
throw new InvalidArgumentException('未初始化配置项,请使用 mail\\lib\\Config::init()初始化配置项');
}
}
}
配置参数固定的写在指定文件不太合适,可以使用类库new的时候传入参数方式
[0] ThrowableError in Transport.php line 120
致命错误: Method name must be a string
} elseif (is_string($driverName)) {
// 驱动为字符串,为内置驱动
$driver = 'create' . ucfirst($driverName) . 'Driver';
if (!method_exists($this, $driver)) {
throw new BadMethodCallException("Mailer driver {$driverName} not exist");
}
}
return $this->$driver();
}
}
config.php 已经填了,但是没有获取
根据文档将 tp-mailer 和 swiftmailer 文件夹复制到 extend 目录中,目录结构如下:
extend
├── tp-mailer
│ └── src
├── swiftmailer
│ ├── lib
│ ├── doc
│ └── tests
在模型中引用
use mailer\tp5\Mailer;
在方法中调用
$mailer = Mailer::instance();
$ret['mailer'] = $mailer->from('***@***.***','***')
->to($strEmail)
->subject($subject)
->html($html)
->send();
报错如下:
Class 'mailer\tp5\Mailer' not found
报错位置:
$mailer = Mailer::instance();
求解决方案,谢谢!
tp5弄了两天,单独弄了composer,结果还是不行,各种bug,也不回复维护,文档不清楚,尬
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.