wascripts/wamailer

电子邮件发送类

v4.0 2021-01-20 21:00 UTC

This package is auto-updated.

Last update: 2024-09-25 23:34:16 UTC


README

介绍

什么是 Wamailer?它是一个由多个类组成的 PHP 库,用于生成和发送电子邮件。Wamailer 尽可能地遵循描述电子邮件语法的不同 RFC。Wamailer 需要 PHP ≥ 5.4.0,并使用 LGPL 许可证发布。

功能

  • 支持 HTML 和多格式(文本和 HTML)电子邮件
  • 直接支持多个收件人、抄送或暗送
  • 支持附件
  • 支持嵌入图像(也适用于其他文件类型)
  • 支持 8bit、quoted-printable 和 base64 转换编码
  • 支持通过 UTF-8 编码的 Unicode
  • 支持 DKIM 签名
  • 添加、修改和删除电子邮件头
  • 将消息重新格式化为每行 78 个字符(自动换行)
  • 完整支持 SMTP
  • 支持 CRAM-MD5、LOGIN 和 PLAIN 认证方法
  • 使用 SSL/TLS 加密连接
  • 支持调用 Sendmail 或兼容系统
  • 支持实验性 OpenPGP/MIME(请参阅 OpenPgp 页面)

使用方法

只需将类包含到您的脚本中。示例用法

// Inclusion de l’autoloader de Wamailer.
// Inutile dans le cas où wamailer est géré par un gestionnaire de
// dépendances tel que composer.
require 'wamailer.php';

$email = new \Wamailer\Email();
$email->setFrom('me@domain.tld', 'MyName');
$email->addRecipient('other@domain.tld');
$email->setSubject('This is the subject');
$email->setTextBody('This is the message');

try {
    \Wamailer\Mailer::send($email);
}
catch (Exception $e) {
    ...
}

第二个示例:使用 SMTP 服务器发送文本和 HTML 电子邮件

use Wamailer\Email;
use Wamailer\Mailer;

require 'wamailer.php';

$email = new Email();
$email->setFrom('me@domain.tld', 'MyName');
$email->addRecipient('other@domain.tld', 'OtherName');
$email->setSubject('This is the subject');
$email->setTextBody('This is the message in plain text format');
$email->setHTMLBody('This is the <strong>message</strong> in HTML format.');

// Sur le port 587, l’option 'starttls' est automatiquement activée.
$opts = [
    'server' => 'mail.mydomain.tld:587',
    'auth'   => ['username' => 'myusername', 'secretkey' => 'mypassword'],
];

try {
    Mailer::setTransport('smtp', $opts);
    Mailer::send($email);
}
catch (Exception $e) {
    ...
}

有关文档的简要说明可在以下 wiki 页面上找到:[http://dev.webnaute.net/wamailer/trac](http://dev.webnaute.net/wamailer/trac) 或 [https://github.com/wascripts/wamailer/wiki](https://github.com/wascripts/wamailer/wiki)

许可证

Wamailer 使用 LGPL 许可证发布。有关更多信息,请参阅 Wamailer 伴随的 COPYING 文件,或访问以下网址:[https://gnu.ac.cn/licenses/lgpl.html](https://gnu.ac.cn/licenses/lgpl.html)

作者