mouf/utils.mailer.mail-interface
Composer 安装命令:
composer require mouf/utils.mailer.mail-interface
包简介
This package contains interfaces and classes describing mails. It also contains the MailerService interface that should be implemented by any service that can send mails. You should use a package implementing this interface (like the SmtpMailer package.
关键字:
README 文档
README
Mouf Mail system
The Mouf framework is only an IOC framework. As such, it does not provide any means for managing any kind of cache. Hopefully, the Mouf team provides also a range of packages to manage sending mails.
The mail architecture
In Mouf, emails are sent using MailServices.
Mouf provides 4 implementations of mail services. You can provide your own if you want.
By default, Mouf provides these 3 implementations:
- SwiftMailService: a mail service that uses a SMTP server to send mails (this is a wrapper using the Swift mail library).
- SmtpMailService: a mail service that uses a SMTP server to send mails (this is a wrapper using the Zend_Mail library).
- DBMailService: a mail service that does not send any mails. Instead, it writes the mail in a MySQL database. It can forward the mail later to another mail service that will actually send the mail. This mail server is available in the package utils/mailer/db-mail-service.
Each mail service must extend the MailServiceInterface interface that is part of the
package utils/mailer/mail-interface.
The mail service interface
Each class implementing the MailServiceInterface provides one simple method to send mails:
interface MailServiceInterface { /** * Sends the mail passed in parameter. * * @param MailInterface $mail The mail to send. */ function send(MailInterface $mail); }
The mail passed in parameter must implement the MailInterface interface. Hopefully, Mouf provides a Mail class
that does just that!
For instance, to send a mail, you just need to write:
$mailService = Mouf::getSmtpMailService(); $mail = new Mail(); $mail->setBodyText("This is my mail!"); $mail->setBodyHtml("This is my <b>mail</b>!"); $mail->setFrom(new MailAddress("my@server.com", "Server")); $mail->addToRecipient(new MailAddress("david@email.com", "David")); $mail->setTitle("My mail"); $mailService->send($mail);
The code above assumes that you configured an instance in Mouf called "smtpMailService".
The MailInterface interface supports:
- Text/Html mails (
setBodyTextandsetBodyHtmlmethods) - Multiple recipients (
addToRecipientmethod) - Multiple Cc recipients (
addCcRecipientmethod) - Multiple Bcc recipients (
addBccRecipientmethod) - File attachments (
addAttachmentmethod)
Mail addresses are passed as a MailAddress object, that contains 2 strings: the mail address and the alias.
Automatic text body generation
When sending mails, it is a good practice to send 2 bodies: one in plain text and one in HTML. Forget the plain text and your mail could be flagged as spam. However, most of the time, your users will look at the mail in HTML. Mail clients that can only read plain text are really rare those days.
The Mail class can help you here. Indeed, it will automatically generate the plain text version of your mail
from the HTML, by stripping all tags.
$mail = new Mail(); $mail->setBodyHtml("This is my <b>mail</b>!"); // No need to call $mail->setBodyText()
If you want to explicitly disable the plain text generation you can call this method:
$mail = new Mail(); $mail->setBodyHtml("This is my <b>mail</b>!"); // Disable plaing text generation from HTML. The mail will NOT contain the plain text part. $mail->autoCreateBodyText(false);
mouf/utils.mailer.mail-interface 适用场景与选型建议
mouf/utils.mailer.mail-interface 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 47.5k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2013 年 05 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「mail」 「mailer」 「interface」 「mouf」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 mouf/utils.mailer.mail-interface 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mouf/utils.mailer.mail-interface 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 mouf/utils.mailer.mail-interface 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Courier offers a convenient and painless solution for creating emails tailored for your Kirby website.
Creates new sare mail transport for laravel applications
Mail libraries used by Zimbra Api
Email+ extends Kirby's email capabilities by adding support for multiple email services using the same Kirby email API.
Mandrill Api Integration for Yii2
Standard PHP Library Extension featuring an ExceptionInterface.
统计信息
- 总下载量: 47.5k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 24
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2013-05-13