rareloop / lumberjack-email
此包的最新版本(v1.4.1)没有提供许可证信息。
v1.4.1
2023-04-05 14:09 UTC
Requires
- rareloop/lumberjack-core: ^5.0.0||^6.0.0
Requires (Dev)
- brain/monkey: ^2.0.2
- mockery/mockery: ^1.0.0
- phpunit/phpunit: ^6.0
- satooshi/php-coveralls: ^1.0
- squizlabs/php_codesniffer: ^3.2
README
此包提供了一个简单的方法,通过Twig模板发送丰富的电子邮件。它是wp_mail()
的一个小包装;
安装后,请在config/app.php
中注册服务提供者
'providers' => [ ... Rareloop\Lumberjack\Email\EmailServiceProvider::class, ... ],
发送电子邮件
您将能够访问Rareloop\Lumberjack\Email\Facades\Email
外观并创建电子邮件
发送HTML电子邮件
use Rareloop\Lumberjack\Email\Facades\Email; Email::sendHTML( 'recipient@mail.com', 'Email Subject line', '<p>Email body goes here</p>' ); // Or with a reply-to email Email::sendHTML( 'recipient@mail.com', 'Email Subject line', '<p>Email body goes here</p>', 'reply-to@mail.com' );
使用Twig模板发送HTML电子邮件
在发送之前,twig文件将被Timber编译。
use Rareloop\Lumberjack\Email\Facades\Email; Email::sendHTMLFromTemplate( 'recipient@mail.com', 'Email Subject line', 'email.twig', [ 'name' => 'Jane Doe' ] // Twig context );
发送纯文本电子邮件
use Rareloop\Lumberjack\Email\Facades\Email; Email::sendPlain( 'recipient@mail.com', 'Email Subject line', 'Plain text body', );
发送带有附件的电子邮件
每个发送方法都接受一个可选的attachments
参数,该参数将按原样传递给wp_mail
。
use Rareloop\Lumberjack\Email\Facades\Email; Email::sendPlain( 'recipient@mail.com', 'Email Subject line', 'Plain text body', false, // Set reply-to to false if you don't need it, necessary because attachments is the final argument ['/path/to/file.pdf'] );
配置
您还可以通过创建一个config/email.php
文件来指定用于电子邮件的SMTP服务器
return [ 'smtp' => [ 'hostname' => '', 'username' => '', 'password' => '', 'auth' => true|false, 'port' => '', ], ];