定制 eoghanobrien/php-simple-mail 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

eoghanobrien/php-simple-mail

Composer 安装命令:

composer require eoghanobrien/php-simple-mail

包简介

Provides a simple, chainable wrapper for creating and sending emails using the PHP mail() function.

关键字:

README 文档

README

Build Status Latest Stable Version Scrutinizer Quality Score Code Coverage Total Downloads License PHP 7 ready

Introduction

Simple Mail Class provides a simple, chainable wrapper for creating and sending emails using the PHP mail() function. There are better options out there for sending SMTP email, which are more secure and more reliable than the mail() function. However, sometimes you just need to send a simple email. That's what we cover.

Installation via Composer

$ composer require eoghanobrien/php-simple-mail

Usage

Instantiating the class.

You have two options, you can 'new up' the class in the traditional way:

$mailer = new SimpleMail();

or instantiate it using the named static constructor make()

$mailer = SimpleMail::make();

The static constructor can be useful when you want to continue chaining methods after instantiating.

SimpleMail::make()
->setTo($email, $name)
->setFrom($fromEmail, $fromName)
->setSubject($subject)
->setMessage($message)
->send();

To header

The To header can be called multiple time, in order to pass more than one To address, simply call the setTo method as many times as needed. It takes two string parameters. The first parameter is for the email address, the second is for the name.

SimpleMail::make()
 ->setTo($email1, $name1)
 ->setTo($email2, $name2);

From header

You can carbon copy one or more addresses using the setBcc method. It takes two string parameters. The first parameter is for the email address, the second is for the name.

SimpleMail::make()
  ->setFrom('john.smith@example.com', 'John Smith');

Cc header

You can carbon copy one or more addresses using the setCc method. It takes an array of $name => $email pairs. Alternatively, you can pass a simple numerically keyed array an the value is assumed to be the email.

SimpleMail::make()
  ->setCc(['John Smith', 'john.smith@example.com');

Bcc header

You can blind carbon copy one or more addresses using the setBcc method. It takes an array of $name => $email pairs. Alternatively, you can pass a simple numerically keyed array an the value is assumed to be the email.

SimpleMail::make()
  ->setBcc(['John Smith', 'john.smith@example.com');

Subject header

You can set the subject using setSubject method. It takes a string as the only parameter.

SimpleMail::make()
    ->setSubject("Important information about your account");

Message header

You can set the message using setMessage method. It takes a string as the only parameter.

SimpleMail::make()
    ->setMessage("My important message!");

HTML emails

If you want to include HTML in your email. Simply call the setHtml() method. It takes no parameters.

SimpleMail::make()
    ->setMessage("<strong>My important message!</strong>")
    ->setHtml();

send emails

Once you've set all your headers. Use the send() method to finally send it on it's way.

SimpleMail::make()
    ->setMessage("<strong>My important message!</strong>")
    ->send();

Full example of sending an email

$send = SimpleMail::make()
    ->setTo($email, $name)
    ->setFrom($fromEmail, $fromName)
    ->setSubject($subject)
    ->setMessage($message)
    ->setReplyTo($replyEmail, $replyName)
    ->setCc(['Bill Gates' => 'bill@example.com'])
    ->setBcc(['Steve Jobs' => 'steve@example.com'])
    ->setHtml()
    ->setWrap(100)
    ->send();
    
echo ($send) ? 'Email sent successfully' : 'Could not send email';

Example of sending an email with attachments

If you are sending an attachment there is no need to add any addGenericHeader()'s. To properly send the attachments the necessary headers will be set for you. You can also chain as many attachments as you want (see example).

$send = SimpleMail::make()
    ->setTo($email, $name)
    ->setFrom($fromEmail, $fromName)
    ->setSubject($subject)
    ->setMessage($message)
    ->setReplyTo($replyEmail, $replyName)
    ->setCc(['Bill Gates' => 'bill@example.com'])
    ->setBcc(['Steve Jobs' => 'steve@example.com'])
    ->setHtml()
    ->setWrap(100)
    ->addAttachment('example/pbXBsZSwgY2hh.jpg', 'lolcat_finally_arrived.jpg')
    ->addAttachment('example/lolcat_what.jpg')
    ->send();
    
echo ($send) ? 'Email sent successfully' : 'Could not send email';

License

php-simple-mail is free and unencumbered public domain software. For more information, see http://opensource.org/licenses/MIT or the accompanying MIT file.

eoghanobrien/php-simple-mail 适用场景与选型建议

eoghanobrien/php-simple-mail 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 35.66k 次下载、GitHub Stars 达 202, 最近一次更新时间为 2014 年 01 月 16 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「email」 「php5」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 eoghanobrien/php-simple-mail 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 eoghanobrien/php-simple-mail 我们能提供哪些服务?
定制开发 / 二次开发

基于 eoghanobrien/php-simple-mail 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 35.66k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 205
  • 点击次数: 12
  • 依赖项目数: 3
  • 推荐数: 0

GitHub 信息

  • Stars: 202
  • Watchers: 17
  • Forks: 87
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-01-16