buzzingpixel/corbomite-mailer

Corbomite Mailer

1.1.0 2019-04-13 19:40 UTC

This package is auto-updated.

Last update: 2024-09-14 06:57:26 UTC


README

BuzzingPixel 的 Corbomite 项目的一部分。

提供事务电子邮件功能。

使用方法

队列

该邮件器使用 Corobmite 队列功能,请确保队列正在运行。

网站管理员邮箱和电子邮件环境变量

为了提高电子邮件的投递率,电子邮件由网站管理员的邮箱发送。请确保设置以下环境变量

  • WEBMASTER_EMAIL_ADDRESS=info@mysite.com
  • WEBMASTER_NAME="Some Name"

CORBOMITE_MAILER_ADAPTER_CLASS 环境变量

要设置邮件器使用的适配器,请确保将 CORBOMITE_MAILER_ADAPTER_CLASS 环境变量设置为适配器类的完全限定名称。内置适配器有

  • buzzingpixel\corbomitemailer\adapters\SendGridSendMailAdapter
  • buzzingpixel\corbomitemailer\adapters\MandrillMailSendMailAdapter
  • buzzingpixel\corbomitemailer\adapters\MailGunSendMailAdapter
  • buzzingpixel\corbomitemailer\adapters\PostMarkSendMailAdapter

您还可以编写自己的适配器。它必须实现 buzzingpixel\corbomitemailer\interfaces\SendMailAdapterInterface

内置适配器环境变量

SendGridSendMailAdapter

要使用 SendGridSendMailAdapter,请确保设置 SENDGRID_API_KEY 环境变量。

MandrillMailSendMailAdapter

要使用 MandrillMailSendMailAdapter,请确保设置 MANDRILL_API_KEY 环境变量。

MailGunSendMailAdapter

要使用 MailGunSendMailAdapter,请确保设置 MAILGUN_API_KEYMAILGUN_DOMAIN 环境变量。

PostMarkSendMailAdapter

要使用 PostMarkSendMailAdapter,请确保设置 POSTMARK_SERVER_TOKEN 环境变量。

发送电子邮件

<?php
declare(strict_types=1);

use corbomite\di\Di;
use buzzingpixel\corbomitemailer\interfaces\EmailApiInterface;

/**
 * Requesting the EmailApiInterface will return an instance of \buzzingpixel\corbomitemailer\EmailApi
 * You can override it with your own implementation by setting to return value of PHP-DI for
 * the interface to your own implementation
 */
$emailApi = Di::diContainer()->get(EmailApiInterface::class);

$emailModel = $this->emailApi->createEmailModel([
    'fromName' => 'Some Name', // Optional, fromEmail must be set
    'fromEmail' => 'Some Email', // Optional
    'toName' => 'Some Name', // Optional
    'toEmail' => 'someone@domain.com', // Required
    'subject' => 'Some Subject', // Required
    'messagePlainText' => 'Plaintext Content', // Required if messageHtml not set. Derived from messageHtml if not set
    'messageHtml' => '<p>Html Content</p>', // Required if messagePlainText not set
]);

// Add the email to the queue and let the queue runner send it (recommended)
$emailApi->addEmailToQueue($emailModel);

// Send the email right away (avoid if possible)
$emailApi->sendEmail($emailModel);

许可证

版权所有 2019 BuzzingPixel, LLC

遵循 Apache 许可证 2.0 版(“许可证”);除非遵守许可证规定,否则不得使用此文件。您可以在 https://apache.ac.cn/licenses/LICENSE-2.0 获取许可证副本。

除非适用法律要求或书面同意,否则根据许可证分发软件属于“按原样”分发,不提供任何明示或暗示的保证或条件。有关许可证中规定的权限和限制的具体语言,请参阅许可证。