slm/mail
Composer 安装命令:
composer require slm/mail
包简介
Integration of various email service providers in the Laminas\Mail
关键字:
README 文档
README
Warning This package relies on slm, which is abandoned and will receive no further development. For that reason, we don't recommend starting any project with this package. Instead take a look at https://github.com/omnimail/omnimail or use symfony/mailer with a 3rd Party Transport.
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
SlmMailin yourapplication.config.phpfile. - 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.phpPlease 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:
slm/mail 适用场景与选型建议
slm/mail 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 746.76k 次下载、GitHub Stars 达 108, 最近一次更新时间为 2013 年 05 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「email」 「postmark」 「sendgrid」 「mandrill」 「mailgun」 「elastic email」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 slm/mail 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 slm/mail 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 slm/mail 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
SendGrid plugin for CakePHP 4 - Send emails using SendGrid API
PHP Library to send email across all platforms using one interface.
Provides an email provider for postmarkapp.com
A collection of monolog handlers using PSR-18 http client
A minor update of Miguel Perez's no-longer maintained code from https://github.com/miguel250/PostmarkBundle to allow for Symfony 3 compatibility. All credit/kudos/thanks for the work should obviously go to him
Componente para integração com serviços de mensageria com APIs externas como Twilio, SendGrid, AWS SES, etc.
统计信息
- 总下载量: 746.76k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 109
- 点击次数: 43
- 依赖项目数: 6
- 推荐数: 1
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2013-05-09