rr/api-mailer

API Service Mailer, which allows PHP applications to send emails through API.

1.0.1 2021-07-19 17:25 UTC

This package is auto-updated.

Last update: 2024-04-29 04:21:37 UTC


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());
}