suny-upstate-cwt/phpmailerqol 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

suny-upstate-cwt/phpmailerqol

Composer 安装命令:

composer require suny-upstate-cwt/phpmailerqol

包简介

PHPMailerQOL is a non-intrusive quality-of-life extension of PHPMailer.

README 文档

README

Highlights

  • setAddress() methods
  • removeAddress() methods
  • Set a default email domain
  • Support multi-address add/set/remove methods
  • addTO() synonym for addAddress()
  • Advanced address parsing
  • Original PHPMailer behavior is not disturbed; just enhanced

License

This software is distributed under the MIT License.

Installation & loading

PHPMailerQOL is available on Packagist (using semantic versioning), and installation via Composer is the recommended way to install PHPMailerQOL. Just add this line to your composer.json file:

"suny-upstate-cwt/phpmailerqol": "^1.0.0"

or run

composer require suny-upstate-cwt/phpmailerqol

Note that the vendor folder and the vendor/autoload.php script are generated by Composer; they are not part of PHPMailerQOL.

Adding and setting addresses

<?php
// Import PHPMailerQOL class into the global namespace
// These must be at the top of your script, not inside a function
use SUNYUpstateCWT\PHPMailerQOL\PHPMailerQOL;

// Load Composer's autoloader (created by composer, not included with PHPMailerQOL)
require 'vendor/autoload.php';

// Create an instance; passing `true` enables parent PHPMailer exceptions
$mail = new PHPMailerQOL(true);

try {
    // Server settings: see PHPMailer docs

    // Set default address domain
    // Append example.com when no domain is detected
    // Domain validation is not performed by PHPMailerQOL
    $mail->setDefaultAddressDomain('example.com');

    // Clear default domain
    // Pass in ANY "empty" or non-scalar value
    // $mail->setDefaultAddressDomain('');
    // $mail->setDefaultAddressDomain(null);
    // $mail->setDefaultAddressDomain([]);

    // Set FROM
    $mail->setFrom('no-reply', 'no-reply');    // Set From: no-reply <no-reply@example.com>

    // Add addresses
    $mail->addAddress([                        // Add TOs:
        'co-worker1'=>'John',                  //     John <co-worker1@example.com>
        'co-worker2'=>'Jim'                    //     Jim <co-worker2@example.com>
    ]);

    // Add addresses and vanity names in separate arrays
    $mail->addAddress([                        // Add TOs:
        ['email1', 'email2'],                  //     email1 <email1@example.com>
        ['Email1 Name', 'Email2 Name'],        //     email2 <email2@example.com>
    ]);

    // Remove previously added TOs and set anew
    $mail->setTO([                             // Set TO:
        'co-worker3',                          //    co-worker3@example.com
        'co-worker4',                          //    co-worker4@example.com
        'client1@otherdomain.com'              //    client1@otherdomain.com
    ]);

    // Add a CC
    $mail->addCC('Some Name <address>');             // This will FAIL; domain must be included
    $mail->addCC('Some Name <address@example.com>'); // Add CC: Some Name <address@example.com>

    // Juggle addresses
    $mail->JuggleAddressAdds = true;
    $mail->addAddress('co-worker3', 'myname');    // co-worker3@example.com is sent to the end of the TO list; with vanity name
    $mail->addBCC('client1@otherdomain.com');     // client1@otherdomain.com is moved to the BCC

    // Content
    $mail->isHTML(true);    //Set email format to HTML
    $mail->Subject = 'My subject';
    $mail->Body    = 'I am <b>bold!</b>';
    $mail->AltBody = 'I am bold!';
    
    $mail->send();
    echo 'Message has been sent';
} catch (Exception $e) {
    echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}

Removing addresses

$mail = new PHPMailerQOL(true);
$mail->setDefaultAddressDomain('example.com');

$mail->addAddress([
    'co-worker1'=>'John',
    'co-worker2'=>'Jim',
    'co-worker4'=>'Jack'
]);
$mail->addBCC('co-worker3');

$mail->removeAddress('co-worker1'); // Bye-bye co-worker1 from TOs
$mail->removeRecipient(['co-worker2','co-worker3@example.com']); // Bye-bye co-worker2 and 3 from TOs, CCs, and BCCs

$mail->Subject = 'My subject';
$mail->Body    = 'Some body';

$mail->send(); // Email sent to just co-worker4@example.com

Send individual emails

$mail = new PHPMailerQOL(true);
$mail->setDefaultAddressDomain('example.com');

$mail->Subject = 'My subject';
$mail->Body    = 'Some body';

// Everyone should get an individual email instead of cramming everyone into the BCC
foreach( $list_of_emails as $email ) {
    $mail->setTO($email);
    $mail->send();
}

suny-upstate-cwt/phpmailerqol 适用场景与选型建议

suny-upstate-cwt/phpmailerqol 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 232 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 10 月 22 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 suny-upstate-cwt/phpmailerqol 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-10-22