rareloop/lumberjack-email

此包的最新版本(v1.4.1)没有提供许可证信息。

v1.4.1 2023-04-05 14:09 UTC

This package is auto-updated.

Last update: 2024-09-05 17:09:33 UTC


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' => '',
    ],
];