定制 pardnchiu/mailer 二次开发

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

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

pardnchiu/mailer

Composer 安装命令:

composer require pardnchiu/mailer

包简介

Lightweight PHP mailer client supporting SMTP sending, automatic configuration management, and complete email functionality. Built on PHPMailer, providing stable and reliable email sending experience.

README 文档

README

Lightweight PHP mail client with SMTP support, automatic configuration management, and complete email functionality.
Built on PHPMailer, providing stable and reliable email delivery experience.

packagist version license
readme readme

Three Core Features

Automatic Configuration Management

Automatically configure connection parameters based on environment variables, supporting multiple SMTP services

Bulk Sending Support

Support bulk email sending functionality, suitable for system notifications and high-volume sending needs

Stable Connection

Built-in error handling and automatic cleanup mechanisms to ensure reliable email delivery

Features

  • Environment Variable Configuration: Flexible environment variable setup supporting multi-environment deployment
  • SMTP Support: Support for multiple SMTP services with automatic encryption configuration
  • HTML/Plain Text: Support for both HTML and plain text email formats
  • Multiple Recipients: Support for multiple recipients, CC, and BCC
  • Priority Settings: Support for high, normal, and low priority email sending
  • Bulk Sending: Built-in bulk sending functionality for improved sending efficiency
  • Automatic Cleanup: Automatic cleanup of recipient lists after sending

Usage

Installation

composer require pardnchiu/mailer

Environment Variables Setup

MAIL_SERVICE=smtp.gmail.com          # SMTP server
MAIL_SERVICE_USER=your@email.com     # Sender account
MAIL_SERVICE_PASSWORD=your_password  # Password or app password
MAIL_SERVICE_PORT=587                # SMTP port (465/587/25)
MAIL_SERVICE_CHARSET=UTF-8           # Character encoding

Basic Usage

Method 1: Static Call (Recommended)

<?php

use pardnchiu\Mailer;

// Direct static call
$result = Mailer::send([
  "email"     => "recipient@example.com",
  "subject"   => "Test Email",
  "body"      => "<h1>This is a test email</h1>",
  "isHtml"    => true
]);

if ($result) {
  echo "Email sent successfully";
} else {
  echo "Email sending failed";
}

Method 2: Instance Call

<?php

use pardnchiu\Mailer;

// Initialize mail client
$mailer = new Mailer();

// Basic email sending (calling static method through instance)
$result = $mailer::send([
  "email"     => "recipient@example.com",
  "subject"   => "Test Email",
  "body"      => "<h1>This is a test email</h1>",
  "isHtml"    => true
]);

if ($result) {
  echo "Email sent successfully";
} else {
  echo "Email sending failed";
}

API Reference

Basic Sending

Mailer::send($config) - Send single email (static call)

$result = Mailer::send([
  "email"     => "recipient@example.com",          // Recipient (required)
  "subject"   => "Email Subject",                  // Subject (required)
  "body"      => "Email Content",                  // Content (required)
  "altBody"   => "Plain text content",             // Plain text version (optional)
  "fromEmail" => "sender@example.com",            // Sender email (optional, defaults to configured account)
  "fromName"  => "Sender Name",                   // Sender name (optional)
  "cc"        => ["cc@example.com"],              // CC (optional)
  "bcc"       => ["bcc@example.com"],             // BCC (optional)
  "priority"  => "high",                          // Priority: high/normal/low (optional)
  "isHtml"    => true                             // HTML format (optional, default false)
]);

Multiple Recipients

$config = [
  "email" => [
    "user1@example.com" => "User One",
    "user2@example.com" => "User Two",
    "user3@example.com"
  ],
  "subject" => "Group Notification",
  "body"    => "This is a group notification email"
];

$result = Mailer::send($config);

CC and BCC

$config = [
  "email"   => "primary@example.com",
  "cc"      => [
    "cc1@example.com" => "CC User One",
    "cc2@example.com"
  ],
  "bcc"     => [
    "bcc1@example.com" => "BCC User One",
    "bcc2@example.com"
  ],
  "subject" => "Important Notice",
  "body"    => "Email content"
];

$result = Mailer::send($config);

Bulk Sending

Mailer::sendBulk($recipients, $subject, $body, $options) - Bulk email sending (static call)

Note: Bulk sending automatically adds a random interval of 1-3 seconds between each email to avoid triggering rate limits from email providers like Gmail and iCloud.

$results = Mailer::sendBulk(
  [
    "user1@example.com" => "User One",
    "user2@example.com" => "User Two",
    "user3@example.com" => "User Three"
  ],
  "Bulk Notification Email",
  "<h1>This is a bulk sent email</h1>",
  [
    "isHtml"    => true,
    "priority"  => "normal",
    "fromName"  => "System Administrator"
  ]
);

// Check sending results
foreach ($results as $email => $success) {
  if ($success) {
    echo "Successfully sent to {$email}\n";
  } else {
    echo "Failed to send to {$email}\n";
  }
}

Error Handling

try {
  $mailer = new Mailer();
  
  $result = Mailer::send([
    "email"   => "test@example.com",
    "subject" => "Test Email",
    "body"    => "Test content"
  ]);
  
  if ($result) {
    echo "Email sent successfully";
  } else {
    echo "Email sending failed";
  }
    
} catch (\Exception $e) {
  error_log("Email sending error: " . $e->getMessage());
  
  if (strpos($e->getMessage(), "SMTP connect() failed") !== false) {
    echo "SMTP connection failed, please check server settings";
  } elseif (strpos($e->getMessage(), "Authentication") !== false) {
    echo "SMTP authentication failed, please check username and password";
  } else {
    echo "Email sending exception: " . $e->getMessage();
  }
}

Connection Test

// Test SMTP connection
try {
  $mailer = new Mailer();
  
  // Send test email
  $result = Mailer::send([
      "email"   => "test@example.com",
      "subject" => "SMTP Connection Test",
      "body"    => "If you receive this email, SMTP configuration is correct."
  ]);
  
  echo $result ? "SMTP configuration is correct" : "SMTP configuration error";
  
} catch (\Exception $e) {
  echo "SMTP test failed: " . $e->getMessage();
}

Bulk Sending Monitoring

$results = Mailer::sendBulk([
    "user1@example.com" => "User One",
    "user2@example.com" => "User Two",
    "user3@example.com" => "User Three"
], "Notification", "Content");

$successCount = array_sum($results);
$totalCount = count($results);
$failureCount = $totalCount - $successCount;

echo "Bulk sending completed - Success: {$successCount}, Failed: {$failureCount}, Total: {$totalCount}";

License

This source code project is licensed under MIT.

Author

邱敬幃 Pardn Chiu

©️ 2025 邱敬幃 Pardn Chiu

pardnchiu/mailer 适用场景与选型建议

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

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-08-24