定制 edward144/php-mailer-failover 二次开发

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

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

edward144/php-mailer-failover

Composer 安装命令:

composer require edward144/php-mailer-failover

包简介

A PHP Mailer class that allows for multiple redundant SMTP services to be configured.

README 文档

README

A PHPMailer class that allows for the configuration of multiple redundant SMTP services. Each service is attempted in turn and if it fails then the next is used. If all services fail then the mail will be logged to a local file for debugging and so that the mail is not lost.

Installation

This package is now on Packagist, so you can simply run composer require edward144/php-mailer-failover.

Create a composer.json file or amend your existing one. Add this Github repository and require the latest version.

{
  "repositories": [
    {
      "type": "vcs",
      "url": "https://github.com/Edward144/PHPMailer-Failover.git"
    }
  ],
  "require": {
    "edward144/php-mailer-failover": "^1.0"
  },
  "minimum-stability": "stable"
}

Run composer install

Configuration

A number of constants must be defined for the class to operate. An example of these can be found within tests/config.example.php. These should be stored in a secure location as your SMTP credentials are required.

  • MAILER_FAILOVER_SMTP - an array of SMTP services to use, these will be attempted in order.

    'service_name' => [
      'host'  => 'smtp.service.com',
      'port' => 587,
      'username' => 'username',
      'password' => 'apikey',
      'encryption' => 'tls' //If omitted then PHPMailer::ENCRYPTION_SMTPS will be used
    ],
    ...
    
  • MAILER_FAILOVER_DEBUG_LEVEL - an integer debug level as defined by PHPMailer, default is 2

    • 0 - Debug off
    • 1 - Client to Server messages
    • 2 - As 1 plus Server to Client messages
    • 3 - As 2 plus connection status
    • 4 - All messages
  • MAILER_FAILOVER_DEBUG_LOCATION - the absolute path to the location where debug logs and failed mails will be stored, include a trailing slash

  • MAILER_FAILOVER_FROM - the default email address that mail will be sent from

  • MAILER_FAILOVER_FROM_FRIENDLY - the default friendlt name that mail will be sent from

Usage

Include the class, require vendor/autoload.php and include your defined constants.

You can then add utilize a variety of methods to configure your mail.


Use Edward144\PHPMailer-Failover\Mailer

require __DIR__ . '/path/to/vendor/autoload.php';
include __DIR__ . '/path/to/config.php';

$mail = new Mailer();

$mail->addTo('john.smith@example.com'); //Add a single address without a friendly name

$mail->addTo('john.smith@example.com', 'John Smith'); //Add a single address with a friendly name

$mail->addTo([
  'john.smith@example.com',
  'jane.doe@example.com'
]); //Add an array of addresses without friendly names

$mail->addTo([
  'John Smith' => 'john.smith@example.com',
  'Jane Doe' => 'jane.doe@example.com'
]); //Add an array of addresses with friendly names

$mail->addTo([
  'John Smith' => 'john.smith@example.com',
  'jane.doe@example.com'
]); //A mix of emails with and without friendlies can be supplied

$mail->addCc($address, $friendly); //Add a CC address, this can be used the same ways as addTo
$mail->addBcc($address, $friendly); //Add a BCC address, this can also be used the same ways as addTo

$mail->subject('This is my subject);
$mail->body('<p>This is my HTML message!</p>, true); //HTML body, a plaintext version is generated by default, pass a second false parameter to omit this
$mail->altBody('This is my plaintext message!'); //Plaintext body, this should be set before the HTML body, unless the automatic plaintext generation has been disabled.

$mail->from('another.from@example.com', 'Optional Friendly Name'); //Override the default from address and friendly name

$mail->addAttachment('absolute/path/to/attachment.txt'); //Add a single attachment

$mail->addAttachment('absolute/path/to/attachment.txt', 'custom-attachment.txt'); //Add a single attachment with a custom filename

$mail->addAttachment([
  'path/to/attachment-1.txt',
  'path/to/attachment-2.pdf'
]); //An array of attachments without custom filenames

$mail->addAttachment([
  'text-attachment.txt' => 'path/to/attachment-1.txt',
  'pdf-attachment.pdf' => 'path/to/attachment-2.pdf'
]); //An array of attachments with custom filenames

$mail->addAttachment([
  'text-attachment.txt' => 'path/to/attachment-1.txt',
  'path/to/attachment-2.pdf'
]); //A mix of attachments with and without custom filenames can be supplied

$mail->send(); //Send the mail
//true will be returned if a service succeeded
//false if all services failed but the message was logged locally
//An error message will be returned in other cases (an incorrect parameter was supplied, the log file failed to open)

Credits

edward144/php-mailer-failover 适用场景与选型建议

edward144/php-mailer-failover 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 7 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 04 月 13 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 edward144/php-mailer-failover 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 7
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 11
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-04-13