Integration of various email service providers in the Laminas\Mail
This package is auto-updated.
Last update: 2021-04-29 00:26:39 UTC
SlmMail is a module that integrates with various third-parties API to send mails. Integration is provided with the API of those services. It does not handle SMTP.
Here are the currently supported services:
- Elastic Email (complete)
- Mailgun (complete)
- Mandrill (complete)
- Postmark (complete)
- Postage (complete)
- Send Grid (nearly complete)
- Spark Post (nearly complete)
- Amazon SES (nearly complete, attachments are missing)
First install the repo:
composer require slm/mail
- For Laminas MVC add
- For Mezzio it should prompt whether we want to autoconfigure. Accept this.
- For Laminas MVC add
In order to use a mail service, you now need to configure it. We have provided a sample configuration file per mail server.
Copy the sample configuration file to your autoload directory. For example for Mandrill one would use
cp vendor/slm/mail/config/slm_mail.mandrill.local.php.dist config/autoload/slm_mail.mandrill.local.php
Please tweak the dummy contents in this file. This file will contain the credentials.
One can now fetch the dependencies from the service manager. And now compose a message:
$message = new \Laminas\Mail\Message(); $message ->setTo('send@to') ->setFrom('send@by') ->setSubject('Subject') ->setBody('Contents'); $mandrillService = $container->get(\SlmMail\Service\MandrillService::class); $mandrillService->send($message);
Documentation for SlmMail is splitted for each provider:
Every email providers used in SlmMail allow to send HTML emails. However, by default, if you set the mail's content
setBody content, this content will be considered as the plain text version as shown below:
$message = new \Laminas\Mail\Message(); // This will be considered as plain text message, even if the string is valid HTML code $message->setBody('Hello world');
To send a HTML version, you must specify the body as a MimeMessage, and add the HTML version as a MIME part, as shown below:
$message = new \Laminas\Mail\Message(); $htmlPart = new \Laminas\Mime\Part('<html><body><h1>Hello world</h1></body></html>'); $htmlPart->type = "text/html"; $textPart = new \Laminas\Mime\Part('Hello world'); $textPart->type = "text/plain"; $body = new \Laminas\Mime\Message(); $body->setParts(array($textPart, $htmlPart)); $message->setBody($body);
For accessibility purposes, you should always provide both a text and HTML version of your mails.
By default the adapter is Laminas\Http\Client\Adapter\Socket but you can override it with other adapter like this in your slm_mail.*.local.php
'slm_mail' => array( // Here your email service provider options 'http_adapter' => 'Laminas\Http\Client\Adapter\Proxy' // for example )
If you want to change some options of your adapter please refer to you adapter class in var $config here and override these in your slm_mail.*.local.php like this :
'slm_mail' => array( // Here your email service provider options // example for Socket adapter 'http_options' => array( 'sslverifypeer' => false, 'persistent' => true, ), )
We won't answer you :-)! Each provider has their own set of features. You should carefully read each website to discover which one suits your needs best.
Currently it is maintained by: