slm / mail
Integration of various email service providers in the Laminas\Mail
Installs: 666 931
Dependents: 7
Suggesters: 2
Security: 0
Stars: 106
Watchers: 13
Forks: 49
Open Issues: 5
Requires
- php: ~7.4.0 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0
- laminas/laminas-http: ^2.8
- laminas/laminas-mail: ^2.9
- laminas/laminas-mime: ^2.8
- laminas/laminas-servicemanager: ^3.11
Requires (Dev)
- ext-json: *
- aws/aws-sdk-php: ^3.208.4
- doctrine/instantiator: ^1.3
- guzzlehttp/guzzle: ^7.4
- laminas/laminas-config: ^3.3
- laminas/laminas-i18n: ^2.10
- laminas/laminas-log: ^2.12
- laminas/laminas-modulemanager: ^2.8
- laminas/laminas-mvc: ^3.1
- laminas/laminas-serializer: ^2.9
- laminas/laminas-view: ^2.11
- phpunit/phpunit: ^9.6.5
- psr/container: ^1.0 || ^2.0
- squizlabs/php_codesniffer: ^3.5
Suggests
- aws/aws-sdk-php: If you need to use Amazon SES
- dev-master
- v5.0.2
- v5.0.1
- v5.0
- v4.7.0
- v4.7.0-alpha.2
- v4.7.0-alpha
- v4.6.0
- v4.5.2
- v4.5
- v4.5-beta
- v4.2.4
- v4.2.3
- v4.2.2
- v4.2.1
- v4.1.7
- v4.1.6
- v4.1.5
- v4.1.4
- v4.1.3
- v4.1.2
- v4.1
- v4.0
- v4.0-alpha
- v3.4
- v3.3
- v3.2
- v3.1
- v3.0
- v3.0-alpha
- v2.1.2
- v2.1.1
- v2.1.0
- v2.0.0
- v1.6.0
- v1.5.3
- v1.5.2
- v1.5.1
- v1.5.0
- v1.4.1
- v1.4.0
- v1.3.2
- v1.3.1
- v1.3.0
- v1.2.0
- v1.1.1
- v1.1.0
- v1.0.1
- v1.0.0
- v1.0.0-rc3
- v1.0.0-rc2
- v1.0.0-rc1
- dev-improve-sparkpost-exceptions
- dev-php8.3
- dev-feature/weaken-options-type
- dev-feature/correct-minimum-version
This package is auto-updated.
Last update: 2024-11-22 11:46:13 UTC
README
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)
- Postmark (complete)
- Postage (complete)
- SendGrid (nearly complete)
- SparkPost (nearly complete)
- Amazon SES (nearly complete, attachments are missing)
- Mandrill (complete, but please don't use this party, as Mailchimp / Mandrill do not actively maintain this service)
Installation
-
First install the repo:
composer require slm/mail
- For Laminas MVC add
SlmMail
in yourapplication.config.php
file. - 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.
Usage
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
Documentation for SlmMail is splitted for each provider:
Cook-book
How to send an HTML email ?
Every email providers used in SlmMail allow to send HTML emails. However, by default, if you set the mail's content
using the 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.
multipart/alternative
emails with attachments
The correct way to compose an email message that contains text, html and attachments is to create a
multipart/alternative
part containing the text and html parts, followed by one or more parts for the attachments. See
the Laminas Documentation
for a full example.
How to configure HttpClient with http_options and http_adapter
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, ), )
Which provider should I choose?
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.
Who to thank?
Jurian Sluiman and Michaël Gallego did the initial work on creating this repo, and maintained it for a long time.
Currently it is maintained by: