rr / api-mailer
API Service Mailer, which allows PHP applications to send emails through 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 Service Mailer, which allows PHP applications to send emails through API.
Choose between the below list which API mail service you want to use.
It reads the configuration from environment
using getenv
.
Installation
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]
Usage
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()); }