Omnimail
Send email across all platforms using one interface
Install / Use
/learn @omnimail/OmnimailREADME
Send email across all platforms using one interface.
Table Of Content
<a name="requirements"></a>
Requirements
This library uses PHP 5.6 and greater version.
<a name="installation"></a>
Installation
It is recommended that you install the Omnimail library through composer. To do so, run the Composer command to install the latest stable version of Omnimail library.
composer require omnimail/omnimail
<a name="providers"></a>
Providers
<a name="amazon-ses"></a>
AmazonSES
Installation
To use the AmazonSES mailer class, you will need to install the daniel-zahariev/php-aws-ses library using composer.
composer require "daniel-zahariev/php-aws-ses:^0.9.2"
Usage
use Omnimail\Email;
use Omnimail\AmazonSES;
$mailer = new AmazonSES($accessKey, $secretKey, $region, $verifyPeer, $verifyHost, $signatureVersion);
$email = (new Email())
->addTo('example@email.com')
->setFrom('example@email.com')
->setSubject('Hello, world!')
->setTextBody('Hello World! How are you?');
$mailer->send($email);
<a name="mailgun"></a>
Mailgun
Installation
To use the Mailgun mailer class, you will need to install the mailgun/mailgun-php library using composer. You do also
need to install a HTTP client that sends messages. You can use any client that provided the virtual package
php-http/client-implementation
composer require mailgun/mailgun-php php-http/guzzle6-adapter
Usage
use Omnimail\Email;
use Omnimail\Mailgun;
$mailer = new Mailgun($apiKey, $domain);
$email = (new Email())
->addTo('example@email.com')
->setFrom('example@email.com')
->setSubject('Hello, world!')
->setTextBody('Hello World! How are you?');
$mailer->send($email);
<a name="mailjet"></a>
Mailjet
Installation
To use the Mailjet mailer class, you will need to install the mailjet/mailjet-apiv3-php library using composer.
composer require mailjet/mailjet-apiv3-php
Usage
use Omnimail\Email;
use Omnimail\Mailjet;
$mailer = new Mailjet($apikey, $apisecret);
$email = (new Email())
->addTo('example@email.com')
->setFrom('example@email.com')
->setSubject('Hello, world!')
->setTextBody('Hello World! How are you?');
$mailer->send($email);
<a name="mandrill"></a>
Mandrill
Installation
To use the Mandrill mailer class, you will need to install the mandrill/mandrill library using composer.
composer require mandrill/mandrill
Usage
use Omnimail\Email;
use Omnimail\Mandrill;
$mailer = new Mandrill($apiKey);
$email = (new Email())
->addTo('example@email.com')
->setFrom('example@email.com')
->setSubject('Hello, world!')
->setTextBody('Hello World! How are you?');
$mailer->send($email);
<a name="postmark"></a>
Postmark
Installation
To use the Postmark mailer class, you will need to install the wildbit/postmark-php library using composer.
composer require wildbit/postmark-php
Usage
use Omnimail\Email;
use Omnimail\Postmark;
$mailer = new Postmark($serverApiToken);
$email = (new Email())
->addTo('example@email.com')
->setFrom('example@email.com')
->setSubject('Hello, world!')
->setTextBody('Hello World! How are you?');
$mailer->send($email);
<a name="sendgrid"></a>
Sendgrid
Installation
To use the Sendgrid mailer class, you will need to install the sendgrid/sendgrid library using composer.
composer require sendgrid/sendgrid
Usage
use Omnimail\Email;
use Omnimail\Sendgrid;
$mailer = new Sendgrid($apiKey);
$email = (new Email())
->addTo('example@email.com')
->setFrom('example@email.com')
->setSubject('Hello, world!')
->setTextBody('Hello World! How are you?');
$mailer->send($email);
<a name="sendinblue"></a>
SendinBlue
Installation
To use the SendinBlue mailer class, you will need to install the mailin-api/mailin-api-php library using composer.
composer require mailin-api/mailin-api-php
Usage
use Omnimail\Email;
use Omnimail\SendinBlue;
$mailer = new SendinBlue($accessKey);
$email = (new Email())
->addTo('example@email.com')
->setFrom('example@email.com')
->setSubject('Hello, world!')
->setTextBody('Hello World! How are you?');
$mailer->send($email);
<a name="smtp"></a>
SMTP
Installation
To use the SMTP mailer class, you will need to install the phpmailer/phpmailer library using composer.
composer require phpmailer/phpmailer
Usage
use Omnimail\Email;
use ShahariaAzam\SMTPMailer\SMTPMailer;
$mailer = new SMTPMailer("SMTP HOSTNAME", "SMTP USERNAME", "SMTP PASSWORD");
$email = (new Email())
->addTo('example@email.com')
->setFrom('example@email.com')
->setSubject('Hello, world!')
->setTextBody('Hello World! How are you?');
$mailer->send($email);
<a name="gmail"></a>
Gmail
Installation
To use the Gmail mailer class, you will need to install the phpmailer/phpmailer library using composer.
composer require phpmailer/phpmailer
Usage
use Omnimail\Email;
use Omnimail\Gmail;
$mailer = new Gmail("you@gmail.com", "password", []);
$email = (new Email())
->addTo('example@email.com')
->setFrom('example@email.com')
->setSubject('Hello, world!')
->setTextBody('Hello World! How are you?');
$mailer->send($email);
<a name="email"></a>
An Email object implements the EmailInterface inteface. You can create your own Email class and send it to any
mailer if it implements the EmailInterface inteface.
<a name="email-to"></a>
To
The To property of the email is for defining the recipients of the email. You can set multiple recipients.
$email = new Email();
$email->addTo('recipent1@email.com', 'Recipient1 Name');
$email->addTo('recipent2@email.com', 'Recipient2 Name');
<a name="email-from"></a>
From
The From property of the email is for defining the mailer of the email.
$email = new Email();
$email->setFrom('sender@email.com', 'Sender Name');
<a name="email-cc"></a>
CC
Like the To property, the CC property can have multiple recipients.
$email = new Email();
$email->addCc('recipent1@email.com', 'Recipient1 Name');
$email->addCc('recipent2@email.com', 'Recipient2 Name');
<a name="email-bcc"></a>
BCC
Like the To property, the BCC property can have multiple recipients.
$email = new Email();
$email->addBcc('recipent1@email.com', 'Recipient1 Name');
$email->addBcc('recipent2@email.com', 'Recipient2 Name');
<a name="email-reply-to"></a>
Reply To
The Reply To property of the email is for defining the email that should receive responses.
$email = new Email();
$email->setReplyTo('sender@email.com', 'Sender Name');
<a name="email-subject"></a>
Subject
The Subject property of the email is for defining the subject of the email.
$email = new Email();
$email->setSubject('Hello, World!');
<a name="email-text-body"></a>
Text Body
The Text Body property of the email is for defining the text body of the email.
$email = new Email();
$email->setTextBody('This is plain text.');
<a name="email-html-body"></a>
HTML Body
The HTML Body property of the email is for defining the HTML body of the email.
$email = new Email();
$email->setHtmlBody('<h1>Hi!</h1><p>This is HTML!</p>');
<a name="email-attachments"></a>
Attachments
The Attachments property of the email is for joining attachments to the email.
Example using string as content
use Omnimail\Email;
use Omnimail\Attachment;
$attachment = new Attachment();
$attachment->setName('my_file.txt');
$attachment->setMimeType('text/plain');
$attachment->setContent('This is plain text');
$email = new Email();
$email->addAttachment($attachment);
Example using file path as content
use Omnimail\Email;
use Omnimail\Attachment;
$attachment = new Attachment();
$att
