【问题标题】:PHP mail() specific questionPHP mail() 特定问题
【发布时间】:2011-08-24 10:04:08
【问题描述】:

所以,我想使用mail() 为我的网站发送注册电子邮件,但是我想让它看起来不错,同时在必要时回退到好的旧明文;混合邮件。

但是我希望它从电子邮件为 johndoe@example.com 的 John Doe 发送到接收者@example.com。

HTML 代码应为<html><head><title>HTML email!</title></head><body><p>This is HTML!</p></body</html>,明文消息应为This is plaintext.

mail() 的参数是什么?我知道其中很多都涉及以某种疯狂的方式更改标题。

非常感谢!

【问题讨论】:

标签: php html email


【解决方案1】:

一切都在这里(示例 #4):http://php.net/manual/en/function.mail.php

【讨论】:

  • 这应该是注释。此外,链接页面上的示例 #4 没有回答 OP 的问题。
【解决方案2】:

改用SwiftMailer 之类的东西,因为它具有防止标头注入等优点。考虑到这一点,是的,您必须设置自定义标题并使用多部分正文来实现您想要的:

/***************************************************************
 Creating Email: Headers, BODY
 1- HTML Email WIthout Attachment!! <<-------- H T M L ---------
 ***************************************************************/
#---->Headers Part
$Headers     =<<<AKAM
From: $FromName <$FromEmail>
Reply-To: $FromEmail
MIME-Version: 1.0
Content-Type: multipart/alternative;
    boundary="$boundary1"
AKAM;

#---->BODY Part
$Body        =<<<AKAM
MIME-Version: 1.0
Content-Type: multipart/alternative;
    boundary="$boundary1"

This is a multi-part message in MIME format.

--$boundary1
Content-Type: text/plain;
    charset="windows-1256"
Content-Transfer-Encoding: quoted-printable

$TextMessage
--$boundary1
Content-Type: text/html;
    charset="windows-1256"
Content-Transfer-Encoding: quoted-printable

$HTMLMessage

--$boundary1--
AKAM;

来源:http://www.php.net/manual/en/function.mail.php#83491

这是很多工作。这也是为什么我建议您拥有一个可以为您处理所有这些以及其他功能的库的原因。

【讨论】:

  • 我认为这是 SwiftMailer 有史以来最好的广告 -- 将组装您自己的 MIME 主体的可怕过程与 SwiftMailer API 的简单魅力进行比较。
猜你喜欢
  • 1970-01-01
  • 2011-09-10
  • 1970-01-01
  • 2013-04-02
  • 1970-01-01
  • 2010-10-08
  • 2021-06-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多