Skip to content
This repository has been archived by the owner on Nov 20, 2024. It is now read-only.
/ api-mailer Public archive

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

Notifications You must be signed in to change notification settings

ramyrabi3/api-mailer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

API Mailer

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
# add Sendgird token to the environment  
SENDGRID_API_KEY=[Sendgrid API Token]
# 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
    '[email protected]', // from
    ['[email protected]'], // 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());
}