developerarts/nomad_mimemail

Nomad MIME Mail 是一个用于处理和发送 MIME 类型邮件的 PHP 类,支持通过 SMTP 和 SMTP 认证进行分发

dev-master 2013-08-28 00:39 UTC

This package is not auto-updated.

Last update: 2024-09-28 14:38:58 UTC


README

描述。

Nomad MIME Mail 是一个用于处理和发送 MIME 类型邮件的 PHP 类,支持通过 SMTP 和 SMTP 认证进行分发

目前,此类支持

  • 纯文本
  • HTML
  • 带附件的纯文本
  • 带附件的 HTML
  • 带嵌入图像的 HTML
  • 带附件和嵌入图像的 HTML

它还支持发送(收件人)多个电子邮件地址,以及抄送(cc)和密送(bcc),以及嵌入在 HTML 中的多个图像和各种附件

快速参考。

与此类和文档一起附带的文件名为 'nomad_mimemail.test.php',其中包含一个通过 SMTP 发送带文本、HTML、图像和副本的示例脚本。

要使用 Nomad MIME Mail,必须按照以下方式声明对象

include ('nomad_mimemail.inc.php');
$mimemail = new nomad_mimemail();

纯文本。

通常,这是函数 'mail ()' 的操作方式。然而,PHP 在这个版本中创建得略有不同,因为它发送了消息体、标题和 MIME 类型

$mimemail->set_from("me@mail.com");
$mimemail->set_to("friend@mail.com");
$mimemail->set_subject("Nomad MIME Mail: Plain Text");
$mimemail->set_text("This is a MIME Mail with:\n\n- Plain Text");

if ($mimemail->send()) {
    echo "The MIME Mail has been sent";
} else {
    echo "An error has occurred, mail was not sent";
} 

纯文本和 HTML。

发送文本和 HTML 的示例

$mimemail->set_from("me@mail.com");
$mimemail->set_to("friend@mail.com");
$mimemail->set_subject("Nomad MIME Mail: Plain Text + HTML");
$mimemail->set_text("This is a MIME Mail with:\n\n- Plain Text\n- HTML");
$mimemail->set_html("<HTML><HEAD></HEAD><BODY>This is a <b>MIME</b> Mail with:<BR><BR>- Plain Text</BR>- HTML</BODY></HTML>");

if ($mimemail->send()) {
    echo "The MIME Mail has been sent";
} else {
    echo "An error has occurred, mail was not sent";
} 

带附件的纯文本。

创建带有附件和纯文本的电子邮件的示例。您可以使用 'add_attachment' 方法添加更多附件。有关更多信息,请参阅函数参考指南。

$mimemail->set_from("me@mail.com");
$mimemail->set_to("friend@mail.com");
$mimemail->set_subject("Nomad MIME Mail: Plain Text + Attachment");
$mimemail->set_text("This is a MIME Mail with:\n\n- Plain Text\n- Attachment");
$mimemail->add_attachment("test_attachment.tar.gz", "file.tar.gz");

if ($mimemail->send()) {
    echo "The MIME Mail has been sent";
} else {
    echo "An error has occurred, mail was not sent";
}

带附件的纯文本和 HTML

创建带有纯文本、HTML 和副本的电子邮件的示例。您可以使用 'add_attachment' 添加多个附件。

$mimemail->set_from("me@mail.com");
$mimemail->set_to("friend@mail.com");
$mimemail->set_subject("Nomad MIME Mail: Plain Text + HTML + Attachment");
$mimemail->set_text("This is a MIME Mail with:\n\n- Plain Text\n- HTML\n- Attachment");
$mimemail->set_html("<HTML><HEAD></HEAD><BODY>This is a <b>MIME</b> Mail with:<BR><BR>- Plain Text</BR>- HTML</BR>- Attachment</BODY></HTML>");
$mimemail->add_attachment("test_attachment.tar.gz", "file.tar.gz");

if ($mimemail->send()) {
    echo "The MIME Mail has been sent";
} else {
    echo "An error has occurred, mail was not sent";
} 

带嵌入图像的纯文本和 HTML

创建带有 HTML、纯文本和嵌入图像的电子邮件的示例。对于嵌入图像功能,附件必须与 HTML 消息中的 'IMG' 标签上指定的名称相同。

$mimemail->set_from("me@mail.com");
$mimemail->set_to("friend@mail.com");
$mimemail->set_subject("Nomad MIME Mail: Plain Text + HTML + Embedded Image");
$mimemail->set_text("This is a MIME Mail with:\n\n- Plain Text\n- HTML\n- Embedded Image");
$mimemail->set_html("<HTML><HEAD></HEAD><BODY>This is a <b>MIME</b> Mail with:<BR><BR>- Plain Text</BR>- HTML</BR>- Embedded Image</BR></BR><img src='image.gif' border='0'></BODY></HTML>");
$mimemail->add_attachment("test_image.gif", "image.gif");

if ($mimemail->send()) {
    echo "The MIME Mail has been sent";
} else {
    echo "An error has occurred, mail was not sent";
}

带嵌入图像和附件的纯文本和 HTML

创建带有 HTML、纯文本、嵌入图像和附件的电子邮件的示例。要使嵌入图像正常工作,附件存档必须与 'IMG' 标签上指定的名称相同。

$mimemail->set_from("me@mail.com");
$mimemail->set_to("friend@mail.com");
$mimemail->set_subject("Nomad MIME Mail: Plain Text + HTML + Embedded Image + Attachment");
$mimemail->set_text("This is a MIME Mail with:\n\n- Plain Text\n- HTML\n- Embedded Image\n- Attachment");
$mimemail->set_html("<HTML><HEAD></HEAD><BODY>This is a <b>MIME</b> Mail with:<BR><BR>- Plain Text</BR>- HTML</BR>- Embedded Image</BR>- Attachment</BR></BR><img src='image.gif' border='0'></BODY></HTML>");
$mimemail->add_attachment("test_image", "image.gif");
$mimemail->add_attachment("test_attachment.tar.gz", "file.tar.gz");

if ($mimemail->send()) {
    echo "The MIME Mail has been sent";
} else {
    echo "An error has occurred, mail was not sent";
}

发送认证 SMTP

要通过 SMTP 发送邮件,必须调用 'set_smtp_host' 方法,并通过 SMTP 认证发送邮件,必须使用 'set_smtp_auth' 方法。

$mimemail->set_from("me@mail.com");
$mimemail->set_to("friend@mail.com");
$mimemail->set_subject("Nomad MIME Mail: HTML + Auth SMTP");
$mimemail->set_html("<HTML><HEAD></HEAD><BODY>This is a <b>MIME</b> Mail with:<BR><BR>- Plain Text</BR>- HTML</BODY></HTML>");

$mimemail->set_smtp_host("domain.com");
$mimemail->set_smtp_auth("user", "pass");

if ($mimemail->send()) {
    echo "The MIME Mail has been sent";
} else {
    echo "An error has occurred, mail was not sent";
}

目前此版本处于测试中,并感谢任何可能的帮助来支持如此大量的 SMTP。如果您有错误,可以审查整个使用 SMTP 的脚本对话。为此,在函数 'send' 调用之前,将 'set_smtp_log' 设置为 true,并通过 'get_smtp_log' 带回一切,如下所示

$mimemail->set_smtp_log(true);

if ($mimemail->send()) {
    echo "The MIME Mail has been sent";
} else {
    echo $mimemail->get_smtp_log();
}

如果是这样,我请您在论坛上留下报告,尽可能详细地记录从 SMTP 收到的响应。