fyre/mail 问题修复 & 功能扩展

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

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

fyre/mail

Composer 安装命令:

composer require fyre/mail

包简介

A mail library.

README 文档

README

FyreMail is a free, open-source email library for PHP.

Table Of Contents

Installation

Using Composer

composer require fyre/mail

In PHP:

use Fyre\Mail\MailManager;

Basic Usage

$mailManager = new MailManager($container);

Default configuration options will be resolved from the "Mail" key in the Config.

Autoloading

It is recommended to bind the MailManager to the Container as a singleton.

$container->singleton(MailManager::class);

Any dependencies will be injected automatically when loading from the Container.

$mailManager = $container->use(MailManager::class);

Methods

Build

Build a Mailer.

  • $options is an array containing configuration options.
$mailer = $mailManager->build($options);

Mailer dependencies will be resolved automatically from the Container.

Clear

Clear all instances and configs.

$mailManager->clear();

Get Config

Get a Mailer config.

  • $key is a string representing the Mailer key.
$config = $mailManager->getConfig($key);

Alternatively, if the $key argument is omitted an array containing all configurations will be returned.

$config = $mailManager->getConfig();

Has Config

Determine whether a Mailer config exists.

  • $key is a string representing the Mailer key, and will default to MailManager::DEFAULT.
$hasConfig = $mailManager->hasConfig($key);

Is Loaded

Determine whether a Mailer instance is loaded.

  • $key is a string representing the Mailer key, and will default to MailManager::DEFAULT.
$isLoaded = $mailManager->isLoaded($key);

Set Config

Set the Mailer config.

  • $key is a string representing the Mailer key.
  • $options is an array containing configuration options.
$mailManager->setConfig($key, $options);

Unload

Unload a Mailer.

  • $key is a string representing the Mailer key, and will default to MailManager::DEFAULT.
$unloaded = $mailManager->unload($key);

Use

Load a shared Mailer instance.

  • $key is a string representing the Mailer key, and will default to MailManager::DEFAULT.
$mailer = $mailManager->use($key);

Mailer dependencies will be resolved automatically from the Container.

Mailers

You can load a specific mailer by specifying the className option of the $options variable above.

Custom mailers can be created by extending \Fyre\Mail\Mailer, ensuring all below methods are implemented.

Email

Create an Email.

$email = $mailer->email();

Get Client

Get the client hostname.

$client = $mailer->getCliet();

Send

Send an Email.

$mailer->send($email);

Debug

The Debug mailer can be loaded using custom configuration.

  • $key is a string representing the mailer key.
  • $options is an array containing configuration options.
    • className must be set to \Fyre\Mail\Handlers\DebugMailer.
    • charset is a string representing the character set, and will default to "utf-8".
    • client is a string representing the client hostname.
$container->use(Config::class)->set('Mail.debug', $options);

Clear

Clear the sent emails.

$mailer->clear();

Get Sent Emails

Get the sent emails.

$sentEmails = $mailer->getSentEmails();

Sendmail

The Sendmail mailer can be loaded using custom configuration.

  • $key is a string representing the mailer key.
  • $options is an array containing configuration options.
    • className must be set to \Fyre\Mail\Handlers\SendmailMailer.
    • charset is a string representing the character set, and will default to "utf-8".
    • client is a string representing the client hostname.
$container->use(Config::class)->set('Mail.sendmail', $options);

SMTP

The SMTP mailer can be loaded using custom configuration.

  • $options is an array containing configuration options.
    • className must be set to \Fyre\Mail\Handlers\SmtpMailer.
    • host is a string representing the SMTP host, and will default to "127.0.0.1".
    • username is a string representing the SMTP username.
    • password is a string representing the SMTP password.
    • port is a number indicating the SMTP port, and will default to 465.
    • auth is a boolean indicating whether to authenticate, and will default to false.
    • tls is a boolean indicating whether to use TLS encryption, and will default to false.
    • dsn is a boolean indicating whether to use delivery status notification, and will default to false.
    • keepAlive is a boolean indicating whether to use a persistent connection, and will default to false.
    • charset is a string representing the character set, and will default to "utf-8".
    • client is a string representing the client hostname.
$container->use(Config::class)->set('Mail.smtp', $options);

Emails

Add Attachments

Add attachments.

  • $attachments is an array containing the attachments, where the key is the filename and the value is an array of attachment data.
    • file is a string representing a path to a file.
    • content is a string representing the file data.
    • mimeType is a string representing the MIME content type.
    • contentId is a string representing the content ID.
    • disposition is a string representing the content disposition.
$email->addAttachments($attachments);

For each attachment, a file or content must be supplied.

If the mimeType is omitted it will determined automatically from the file data.

If the disposition is omitted, it will default to "inline" if a contentId is provided, otherwise "attachment".

Add Bcc

Add a bcc address.

  • $email is a string representing the email address.
  • $name is a string representing the name, and will default to the email address.
$email->addBcc($email, $name);

Add Cc

Add a cc address.

  • $email is a string representing the email address.
  • $name is a string representing the name, and will default to the email address.
$email->addCc($email, $name);

Add Reply To

Add a reply to address.

  • $email is a string representing the email address.
  • $name is a string representing the name, and will default to the email address.
$email->addReplyTo($email, $name);

Add To

Add a to address.

  • $email is a string representing the email address.
  • $name is a string representing the name, and will default to the email address.
$email->addTo($email, $name);

Get Attachments

Get the attachments.

$attachments = $email->getAttachments();

Get Bcc

Get the bcc addresses.

$bcc = $email->getBcc();

Get Body HTML

Get the HTML body string.

$html = $email->getBodyHtml();

Get Body Text

Get the text body string.

$text = $email->getBodyText();

Get Boundary

Get the boundary.

$boundary = $email->getBoundary();

Get Cc

Get the cc addresses.

$cc = $email->getCc();

Get Charset

Get the character set.

$charset = $email->getCharset();

Get Format

Get the email format.

$format = $email->getFormat();

Get From

Get the from addresses.

$from = $email->getFrom();

Get Headers

Get the additional headers.

$headers = $email->getHeaders();

Get Message ID

Get the message ID.

$messageId = $email->getMessageId();

Get Priority

Get the priority.

$priority = $email->getPriority();

Get Read Receipt

Get the read recipient addresses.

$readReceipt = $email->getReadReceipt();

Get Recipients

Get the recipient addresses.

$recipients = $email->getRecipients();

Get Reply To

Get the reply to addresses.

$replyTo = $email->getReplyTo();

Get Return Path

Get the return path addresses.

$returnPath = $email->getReturnPath();

Get Sender

Get the sender addresses.

$sender = $email->getSender();

Get Subject

Get the subject.

$subject = $email->getSubject();

Get To

Get the to addresses.

$to = $email->getTo();

Send

Send the email.

$email->send();

Set Attachments

Set the attachments.

  • $attachments is an array containing the attachments, where the key is the filename and the value is an array of attachment data.
    • file is a string representing a path to a file.
    • content is a string representing the file data.
    • mimeType is a string representing the MIME content type.
    • contentId is a string representing the content ID.
    • disposition is a string representing the content disposition.
$email->setAttachments($attachments);

For each attachment, a file or content must be supplied.

If the mimeType is omitted it will determined automatically from the file data.

If the disposition is omitted, it will default to "inline" if a contentId is provided, otherwise "attachment".

Set Bcc

Set the bcc addresses.

  • $emails is an array containing the email addresses, or key-value pairs of email addresses and names.
$email->setBcc($emails);

Set Body Html

Set the body HTML.

  • $html is a string representing the body HTML.
$email->setBodyHtml($html);

Set Body Text

Set the body text.

  • $text is a string representing the body text.
$email->setBodyText($text);

Set Cc

Set the cc addresses.

  • $emails is an array containing the email addresses, or key-value pairs of email addresses and names.
$email->setCc($emails);

Set Charset

Set the character set.

  • $charset is a string representing the character set.
$email->setCharset($charset);

Set Format

Set the email format.

  • $format is a string representing the email format, and must be one of either "html", "text", or "both".
$email->setFormat($format);

Set From

Set the from address.

  • $email is a string representing the email address.
  • $name is a string representing the name, and will default to the email address.
$email->setFrom($email, $name);

Set Headers

Set additional headers.

  • $headers is an array containing additional headers.
$email->setHeaders($headers);

Set Priority

Set the priority.

$email->setPriority($priority);

Set Read Receipt

Set the read recipient address.

  • $email is a string representing the email address.
  • $name is a string representing the name, and will default to the email address.
$email->setReadReceipt($email, $name);

Set Reply To

Set the reply to addresses.

  • $emails is an array containing the email addresses, or key-value pairs of email addresses and names.
$email->setReplyTo($emails);

Set Return Path

Set the return path address.

  • $email is a string representing the email address.
  • $name is a string representing the name, and will default to the email address.
$email->setReturnPath($email, $name);

Set Sender

Set the sender address.

  • $email is a string representing the email address.
  • $name is a string representing the name, and will default to the email address.
$email->setSender($email, $name);

Set Subject

Set the subject.

  • $subject is a string representing the subject.
$email->setSubject($subject);

Set To

Set the to addresses.

  • $emails is an array containing the email addresses, or key-value pairs of email addresses and names.
$email->setTo($emails);

fyre/mail 适用场景与选型建议

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-12-13