百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
O

omnimail

> 编程语言
开源

使用一个界面在所有平台上发送电子邮件

330 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

使用一个界面在所有平台上发送电子邮件

Send email across all platforms using one interface.

Table Of Content

  1. Requirements
  2. Installation
  3. Providers
    • AmazonSES
    • Mailgun
    • Mailjet
    • Mandrill
    • Postmark
    • Sendgrid
    • SendinBlue
    • SMTP
    • Gmail
  4. Email
    • To
    • From
    • CC
    • BCC
    • Reply to
    • Subject
    • Text Body
    • HTML Body
    • Attachments
  5. Mass Mailings
  6. Factory
  7. Exceptions
  8. Logging
  9. License

Requirements

This library uses PHP 5.6 and greater version.

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.

bash
composer require omnimail/omnimail

Providers

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

php
use Omnimail\Email;
use Omnimail\AmazonSES;

$mailer = new AmazonSES($accessKey, $secretKey, $region, $verifyPeer, $verifyHost, $signatureVersion);

$email = (new Email())
    ->addTo('[email protected]')
    ->setFrom('[email protected]')
    ->setSubject('Hello, world!')
    ->setTextBody('Hello World! How are you?');

$mailer->send($email);

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

php
use Omnimail\Email;
use Omnimail\Mailgun;

$mailer = new Mailgun($apiKey, $domain);

$email = (new Email())
    ->addTo('[email protected]')
    ->setFrom('[email protected]')
    ->setSubject('Hello, world!')
    ->setTextBody('Hello World! How are you?');

$mailer->send($email);

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

php
use Omnimail\Email;
use Omnimail\Mailjet;

$mailer = new Mailjet($apikey, $apisecret);

$email = (new Email())
    ->addTo('[email protected]')
    ->setFrom('[email protected]')
    ->setSubject('Hello, world!')
    ->setTextBody('Hello World! How are you?');

$mailer->send($email);

Mandrill

Installation

To use the Mandrill mailer class, you will need to install the mandrill/mandrill library using composer.

composer require mandrill/mandrill

Usage

php
use Omnimail\Email;
use Omnimail\Mandrill;

$mailer = new Mandrill($apiKey);

$email = (new Email())
    ->addTo('[email protected]')
    ->setFrom('[email protected]')
    ->setSubject('Hello, world!')
    ->setTextBody('Hello World! How are you?');

$mailer->send($email);

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

php
use Omnimail\Email;
use Omnimail\Postmark;

$mailer = new Postmark($serverApiToken);

$email = (new Email())
    ->addTo('[email protected]')
    ->setFrom('[email protected]')
    ->setSubject('Hello, world!')
    ->setTextBody('Hello World! How are you?');

$mailer->send($email);

Sendgrid

Installation

To use the Sendgrid mailer class, you will need to install the sendgrid/sendgrid library using composer.

composer require sendgrid/sendgrid

Usage

php
use Omnimail\Email;
use Omnimail\Sendgrid;

$mailer = new Sendgrid($apiKey);

$email = (new Email())
    ->addTo('[email protected]')
    ->setFrom('[email protected]')
    ->setSubject('Hello, world!')
    ->setTextBody('Hello World! How are you?');

$mailer->send($email);

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

php
use Omnimail\Email;
use Omnimail\SendinBlue;

$mailer = new SendinBlue($accessKey);

$email = (new Email())
    ->addTo('[email protected]')
    ->setFrom('[email protected]')
    ->setSubject('Hello, world!')
    ->setTextBody('Hello World! How are you?');

$mailer->send($email);

SMTP

Installation

To use the SMTP mailer class, you will need to install the phpmailer/phpmailer library using composer.

composer require phpmailer/phpmailer

Usage

php
use Omnimail\Email;
use ShahariaAzam\SMTPMailer\SMTPMailer;

$mailer = new SMTPMailer("SMTP HOSTNAME", "SMTP USERNAME", "SMTP PASSWORD");

$email = (new Email())
    ->addTo('[email protected]')
    ->setFrom('[email protected]')
    ->setSubject('Hello, world!')
    ->setTextBody('Hello World! How are you?');

$mailer->send($email);

Gmail

Installation

To use the Gmail mailer class, you will need to install the phpmailer/phpmailer library using composer.

composer require phpmailer/phpmailer

Usage

php
use Omnimail\Email;
use Omnimail\Gmail;

$mailer = new Gmail("[email protected]", "password", []);

$email = (new Email())
    ->addTo('[email protected]')
    ->setFrom('[email protected]')
    ->setSubject('Hello, world!')
    ->setTextBody('Hello World! How are you?');

$mailer->send($email);

Email

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.

To

The To property of the email is for defining the recipients of the email. You can set multiple recipients.

php
$email = new Email();
$email->addTo('[email protected]', 'Recipient1 Name');
$email->addTo('[email protected]', 'Recipient2 Name');

From

The From property of the email is for defining the mailer of the email.

php
$email = new Email();
$email->setFrom('[email protected]', 'Sender Name');

CC

Like the To property, the CC property can have multiple recipients.

php
$email = new Email();
$email->addCc('[email protected]', 'Recipient1 Name');
$email->addCc('[email protected]', 'Recipient2 Name');

BCC

Like the To property, the BCC property can have multiple recipients.

php
$email = new Email();
$email->addBcc('[email protected]', 'Recipient1 Name');
$email->addBcc('[email protected]', 'Recipient2 Name');

Reply To

The Reply To property of the email is for defining the email that should receive responses.

php
$email = new Email();
$email->setReplyTo('[email protected]', 'Sender Name');

Subject

The Subject property of the email is for defining the subject of the email.

php
$email = new Email();
$email->setSubject('Hello, World!');

Text Body

The Text Body property of the email is for defining the text body of the email.

php
$email = new Email();
$email->setTextBody('This is plain text.');

HTML Body

The HTML Body property of the email is for defining the HTML body of the email.

php
$email = new Email();
$email->setHtmlBody('
Hi!

This is HTML!
');

Attachments

The Attachments property of the email is for joining attachments to the email.

Example using string as content

php
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

php
use Omnimail\Email;
use Omnimail\Attachment;

$attachment = new Attachment();
$attachment->setMimeType('text/plain');
$attachment->setPath(__DIR__ . '/my_file.txt');

$email = new Email();
$email->addAttachment($attachment);

Inline attachments

php
use Omnimail\Email;
use Omnimail\Attachment;

$attachment = new Attachment();
$attachment->setPath(__DIR__ . '/image.png');
$attachment->setContentId('image.png');

$email = new Email();
$email->setHtmlBody('
Hello!
');
$email->addAttachment($attachment);

Factory

Alternatively, you can use the factory method to create a mailer. Consider the following example to create a AmazonSES mailer:

php
use Omnimail\Omnimail;

$mailer = Omnimail::create(Omnimail::AMAZONSES, ['accessKey' => $accessKey, 'secretKey' => $secretKey]);

Mass Mailings

The mass mailing component is for interacting with mass mailing providers. Currently the code focusses on data retrieval, but in future it should also define creating and sending mass mailings.

There are 2 functions currently described for the Mass mailings interface getMailings and getRecipients.

getMailings

…

getMailings

…

Exceptions

Failures to send emails will throw exceptions.

Exceptions

  • Omnimail\Exception\Exception
  • Omnimail\Exception\EmailDeliveryException
  • Omnimail\Exception\InvalidRequestException
  • Omnimail\Exception\UnauthorizedException
  • Omnimail\Exception\MailerNotFoundException

To catch all exception, consider the following.

php
try {
    $mailer->send($email);
} catch (\Omnimail\Exception\Exception $e) {
    echo 'Something went wrong: ' . $e->getMessage();
}

To catch specific exceptions, consider the following.

php
try {
    $mailer->send($email);
} catch (\Omnimail\Exception\UnauthorizedException $e) {
    echo 'Your credentials must be incorrect';
} catch (\Omnimail\Exception\InvalidRequestException $e) {
    echo 'The request is badly formatted, check that all required fields are filled.';
} catch (\Omnimail\Exception\EmailDeliveryException $e) {
    echo 'The email did not go out.';
}

Logging

All mailers constructors take a PSR-3 compatible logger.

Email sent (including the email) are logged at INFO level. Errors (including the email) are reported at the ERROR level.

Example using Monolog

php
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
use Omnimail\Mailgun;

$logger = new Logger('name');
$logger->pushHandler(new StreamHandler('path/to/your.log', Logger::INFO));

$mailer = new Mailgun($apiKey, $domain, $logger);
$mailer->send($email);

License

Omnimail is licensed under The MIT License (MIT).

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

PHPamazonsesemailemail-sendermailgun

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言