nordsoftware / lumen-mandrill-mailer
此包已被放弃,不再维护。未建议替代包。
Lumen PHP 框架的 Mandrill 邮件发送器。
0.1.1
2016-03-01 15:00 UTC
Requires
- mandrill/mandrill: ^1.0
- vlucas/phpdotenv: ~2.2
Requires (Dev)
- laravel/lumen-framework: ~5.2
This package is not auto-updated.
Last update: 2020-01-24 16:13:42 UTC
README
Lumen PHP 框架的 Mandrill 邮件发送器。
通过 Mandrill API 发送电子邮件消息,可以使用模板或纯文本邮件。
安装
// .env:
MANDRILL_API_KEY=<ANY_VALID_API_KEY>
MANDRILL_PRETEND=<TRUE|FALSE>
// config/mandrillmailer.php
return [
'secret' => env('MANDRILL_API_KEY'),
'pretend' => env('MANDRILL_PRETEND', false),
];
// bootstrap/app.php
...
$app->configure('mandrillmailer');
...
$app->register(Nord\Lumen\Mandrill\Mailer\MandrillMailServiceProvider::class);
使用方法
您可以将发送 Mandrill 邮件的支持添加到应用程序的任何部分。使用 SendsEmails
特性来实现
...
use \Nord\Lumen\Mandrill\Mailer\App\SendsEmails;
...
然后在您的代码中稍后,您可以使用函数 $this->sendRaw(MandrillMailMessage $message)
发送原始消息,或使用 $this->sendTemplate(MandrillMailMessage $message)
发送模板邮件。您需要构建要发送的消息
...
$message = new \Nord\Lumen\Mandrill\Mailer\Infrastructure\MandrillMailMessage(
['Recipient Name' => 'email@recipient.com'], // To address.
['From Name' => 'email@from.com'], // From address.
'Email Subject', // Subject.
[ // Message body.
'html' => '<h1>Message body HTML</h1>',
'text' => 'Message body plain text',
'data' => [
'templateVariableName' => 'TemplateVariableValue',
'firstName' => 'First Name',
'lastName' => 'Last Name',
...
],
],
'template-name', // Mandrill template name. Optional.
[
'templateContent' // Template content. Optional.
],
'cc@email.com', // CC Address. Optional.
'bcc@email.com', // BCC Address. Optional.
[ // Attachments. Optional.
[
'type' => 'image/png', // Required field.
'name' => 'attachment1.png', // Required field.
'content' => base64_encode(file_get_contents(/full/path/to/attachment1.png)), // Required field.
],
[
'type' => 'image/png',
'name' => 'attachment2.png',
'content' => base64_encode(file_get_contents(/full/path/to/attachment2.png)),
],
],
[ // Headers. Optional
'Reply-To' => 'reply-to@email.com',
],
[ // Images. Optional.
[
'type' => 'image/png', // Required field.
'name' => 'image1.png', // Required field.
'content' => base64_encode(file_get_contents(/full/path/to/image1.png)), // Required field.
],
],
);
...
许可证
见 LICENSE。