developarts / nomad_mimemail
Nomad MIME Mail 是一个用于处理和发送 MIME 类型邮件的 PHP 类,支持通过 SMTP 和 SMTP Auth 进行分发
Requires
- php: >=5.1.0
This package is auto-updated.
Last update: 2024-09-29 03:58:03 UTC
README
Nomad MIME Mail 是一个用于处理和发送 MIME 类型邮件的 PHP 类,支持通过 SMTP 和 SMTP Auth 进行分发
描述。
目前,此类支持以下内容:
- 纯文本
- HTML
- 带附件的纯文本
- 带附件的HTML
- 嵌入图像的HTML
- 带附件和嵌入图像的HTML
它还支持发送到多个电子邮件地址(收件人),包括副本(cc)和盲副本(bcc),以及嵌入在 HTML 中的多个图像和各种附件
快速参考。
与此类和文档一起附带的文件名为 'nomad_mimemail.test.php',其中包含一个通过 SMTP 发送文本、HTML、图像和代理嵌入的示例脚本。
要使用 MIME Mail Nomad,需要按照以下方式声明对象
include ('nomad_mimemail.inc.php'); $mimemail = new nomad_mimemail();
纯文本。
通常,这将是 PHP 中 'mail()' 函数的工作方式。然而,在这个版本中,它被创建得略有不同,因为它发送了消息的主体、头信息和 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 收到的响应。