Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Send email across all platforms using one interface

License

NotificationsYou must be signed in to change notification settings

omnimail/omnimail

Repository files navigation

Build StatusScrutinizer Code QualityCode CoverageLatest Stable VersionJoin the chat at https://gitter.im/omnimail/omnimail

Send email across all platforms using one interface.

Table Of Content

  1. Requirements
  2. Installation
  3. Providers
  4. Email
  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 librarythrough composer. To do so,run the Composer command to install the latest stable version of Omnimail library.

composer require omnimail/omnimail

Providers

AmazonSES

Installation

To use the AmazonSES mailer class, you will need to install thedaniel-zahariev/php-aws-ses library using composer.

composer require "daniel-zahariev/php-aws-ses:^0.9.2"

Usage

useOmnimail\Email;useOmnimail\AmazonSES;$mailer =newAmazonSES($accessKey,$secretKey,$region,$verifyPeer,$verifyHost,$signatureVersion);$email = (newEmail())    ->addTo('example@email.com')    ->setFrom('example@email.com')    ->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 themailgun/mailgun-php library using composer. You do alsoneed to install a HTTP client that sends messages. You can use any client that provided the virtual packagephp-http/client-implementation

composer require mailgun/mailgun-php php-http/guzzle6-adapter

Usage

useOmnimail\Email;useOmnimail\Mailgun;$mailer =newMailgun($apiKey,$domain);$email = (newEmail())    ->addTo('example@email.com')    ->setFrom('example@email.com')    ->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 themailjet/mailjet-apiv3-php library using composer.

composer require mailjet/mailjet-apiv3-php

Usage

useOmnimail\Email;useOmnimail\Mailjet;$mailer =newMailjet($apikey,$apisecret);$email = (newEmail())    ->addTo('example@email.com')    ->setFrom('example@email.com')    ->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 themandrill/mandrill library using composer.

composer require mandrill/mandrill

Usage

useOmnimail\Email;useOmnimail\Mandrill;$mailer =newMandrill($apiKey);$email = (newEmail())    ->addTo('example@email.com')    ->setFrom('example@email.com')    ->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 thewildbit/postmark-php library using composer.

composer require wildbit/postmark-php

Usage

useOmnimail\Email;useOmnimail\Postmark;$mailer =newPostmark($serverApiToken);$email = (newEmail())    ->addTo('example@email.com')    ->setFrom('example@email.com')    ->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 thesendgrid/sendgrid library using composer.

composer require sendgrid/sendgrid

Usage

useOmnimail\Email;useOmnimail\Sendgrid;$mailer =newSendgrid($apiKey);$email = (newEmail())    ->addTo('example@email.com')    ->setFrom('example@email.com')    ->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 themailin-api/mailin-api-php library using composer.

composer require mailin-api/mailin-api-php

Usage

useOmnimail\Email;useOmnimail\SendinBlue;$mailer =newSendinBlue($accessKey);$email = (newEmail())    ->addTo('example@email.com')    ->setFrom('example@email.com')    ->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 thephpmailer/phpmailer library using composer.

composer require phpmailer/phpmailer

Usage

useOmnimail\Email;useShahariaAzam\SMTPMailer\SMTPMailer;$mailer =newSMTPMailer("SMTP HOSTNAME","SMTP USERNAME","SMTP PASSWORD");$email = (newEmail())    ->addTo('example@email.com')    ->setFrom('example@email.com')    ->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 thephpmailer/phpmailer library using composer.

composer require phpmailer/phpmailer

Usage

useOmnimail\Email;useOmnimail\Gmail;$mailer =newGmail("you@gmail.com","password", []);$email = (newEmail())    ->addTo('example@email.com')    ->setFrom('example@email.com')    ->setSubject('Hello, world!')    ->setTextBody('Hello World! How are you?');$mailer->send($email);

Email

AnEmail object implements theEmailInterface inteface. You can create your ownEmail class and send it to anymailer if it implements theEmailInterface inteface.

To

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

$email =newEmail();$email->addTo('recipent1@email.com','Recipient1 Name');$email->addTo('recipent2@email.com','Recipient2 Name');

From

TheFrom property of the email is for defining the mailer of the email.

$email =newEmail();$email->setFrom('sender@email.com','Sender Name');

CC

Like theTo property, theCC property can have multiple recipients.

$email =newEmail();$email->addCc('recipent1@email.com','Recipient1 Name');$email->addCc('recipent2@email.com','Recipient2 Name');

BCC

Like theTo property, theBCC property can have multiple recipients.

$email =newEmail();$email->addBcc('recipent1@email.com','Recipient1 Name');$email->addBcc('recipent2@email.com','Recipient2 Name');

Reply To

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

$email =newEmail();$email->setReplyTo('sender@email.com','Sender Name');

Subject

TheSubject property of the email is for defining the subject of the email.

$email =newEmail();$email->setSubject('Hello, World!');

Text Body

TheText Body property of the email is for defining the text body of the email.

$email =newEmail();$email->setTextBody('This is plain text.');

HTML Body

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

$email =newEmail();$email->setHtmlBody('<h1>Hi!</h1><p>This is HTML!</p>');

Attachments

TheAttachments property of the email is for joining attachments to the email.

Example using string as content

useOmnimail\Email;useOmnimail\Attachment;$attachment =newAttachment();$attachment->setName('my_file.txt');$attachment->setMimeType('text/plain');$attachment->setContent('This is plain text');$email =newEmail();$email->addAttachment($attachment);

Example using file path as content

useOmnimail\Email;useOmnimail\Attachment;$attachment =newAttachment();$attachment->setMimeType('text/plain');$attachment->setPath(__DIR__ .'/my_file.txt');$email =newEmail();$email->addAttachment($attachment);

Inline attachments

useOmnimail\Email;useOmnimail\Attachment;$attachment =newAttachment();$attachment->setPath(__DIR__ .'/image.png');$attachment->setContentId('image.png');$email =newEmail();$email->setHtmlBody('<p>Hello!</p><img src="cid:image.png">');$email->addAttachment($attachment);

Factory

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

useOmnimail\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 interfacegetMailings andgetRecipients.

getMailings

$mailer = Omnimail::create('Silverpop',array('credentials' =>newCredentials(array('username' =>$userName...)))->getMailings();$mailer->setStartTimeStamp(strtotime('7 days ago'));$mailer->setEndTimeStamp(strtotime('now'));// Instead of using set methods a Credentials object can be passed in ie.// Omnimail::create('Silverpop', array('credentials' => new Credentials(array('username' => $userName...)));// The advantage of using the Credentials object is that the object will not disclose// the credentials when var_dump or similar is called, helping to make the code// more secure.$mailings =$mailer->getResponse();for ($i =0;$i <15;$i++) {if (!$mailings->isCompleted()) {sleep(15);      }else {foreach (\Omnimail\Common\Responses\BaseResponse$mailingsas \Omnimail\Common\Responses\Mailing$mailing) {$detail =>array('subject' =>$mailing→getSubject(),'external_identifier' =>$mailing->getMailingIdentifier(),'name' =>$mailing->getName(),'scheduled_date' =>$mailing->getScheduledDate(),'start_date' =>$mailing->getSendStartDate(),'number_sent' =>$mailing->getNumberSent(),'body_html' =>$mailing->getHtmlBody(),'body_text' =>$mailing→getTextBody(),// Note that in the case of Silverpop these statistics are not retrieved by the// same api call. This is invisible to the calling function, and unless// stats are requested they are not retrieved.'number_bounced' =>$mailing->getNumberBounces(),'number_opened_total' =>$mailing->getNumberOpens(),'number_opened_unique' =>$mailing->getNumberUniqueOpens(),'number_unsubscribed' =>$mailing->getNumberUnsubscribes(),'number_suppressed' =>$mailing->getNumberSuppressedByProvider(),// 'forwarded''number_blocked' =>$mailing->getNumberBlocked(),// 'clicked_total' => $stats['NumGrossClick'],'number_abuse_complaints' =>$mailing->getNumberAbuseReports(),            );          }      }    }

getMailings

$mailer = Omnimail::create('Silverpop')->getRecipients();$mailer->setUserName($userName);$mailer->setPassword($password);$mailer->setStartTimeStamp(strtotime('7 days ago'));$mailer->setEndTimeStamp(strtotime('now'));$mailer->setMailingIdentifier(123);$recipients =$mailer->getResponse();if (!$recipients->isCompleted()) {// sleep or exit & retry later.    }foreach (\Omnimail\Responses\RecipientsResponse$recipientsas \Omnimail\Responses\Recipient$$recipient) {$detail =>array('external_identifier' =>$mailing->getMailingIdentifier(),'email' =>$mailing->getEmail(),'provider_contact_id' =>$mailing->getContactIdentifier(),'contact_id' =>$mailing->GetContactReference(),// Const ACTION_SENT = ‘Sent’, ACTION_OPENED = ‘Open’, ...'action' =>$mailing->getRecipientAction(),'timestamp' =>getRecipientActionTimestamp(),     );

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.

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

To catch specific exceptions, consider the following.

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

useMonolog\Logger;useMonolog\Handler\StreamHandler;useOmnimail\Mailgun;$logger =newLogger('name');$logger->pushHandler(newStreamHandler('path/to/your.log', Logger::INFO));$mailer =newMailgun($apiKey,$domain,$logger);$mailer->send($email);

License

Omnimail is licensed underThe MIT License (MIT).

About

Send email across all platforms using one interface

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors9

Languages


[8]ページ先頭

©2009-2025 Movatter.jp