rr / api-mailer
API 服务邮件发送器,允许 PHP 应用通过 API 发送电子邮件。
1.0.1
2021-07-19 17:25 UTC
Requires
- php: ^7.3|^8.0
- mailjet/mailjet-apiv3-php: ^1.5
- sendgrid/sendgrid: ~7
Requires (Dev)
- phpunit/phpunit: ^9.3.3
README
API 服务邮件发送器,允许 PHP 应用通过 API 发送电子邮件。
从以下列表中选择您想使用的 API 邮件服务。它使用 getenv
从 环境
读取配置。
安装
composer require rr/api-mailer
Sendgrid
# add Sendgird token to the environment
SENDGRID_API_KEY=[Sendgrid API Token]
Mailjet
# add Mailjet tokens to the environment. # Mailjet API version used is v3.1 MJ_APIKEY_PUBLIC=[Mailjet API Public Key] MJ_APIKEY_PRIVATE=[Mailjet API Secret Key]
使用方法
require 'vendor/autoload.php'; $mailer = \RR\ApiMailer\ApiMailer::getMailerInstance('sendgrid'); // sendgrid | mailjet $message = new \RR\ApiMailer\Message( 'this is subject', // subject 'from@gmail.com', // from ['to@gmail.com'], // array of recipients 'this is text', // plain text email body '<h1>this is HTML content</h1>' // HTML email body ); $result = $mailer->send($message); if ($result === true) { echo 'Successfully sent'; } else { // Error var_dump($mailer->getError()); }