简体   繁体   English

PHP mail()特定问题

[英]PHP mail() specific question

So, I would like to use mail() to send registration emails for my website, however I'd like to make it look nice while falling back to good old plaintext when necessary; 因此,我想使用mail()为我的网站发送注册电子邮件,但是我想使它看起来不错,同时在必要时使用旧的纯文本格式; a mixed message email. 混合邮件电子邮件。

However I would like it to be sent from John Doe who's email is johndoe@example.com to recipient@example.com. 但是,我希望将其从John Doe的电子邮件发送到johndoe@example.com,并将其发送到receive@example.com。

The HTML code should be <html><head><title>HTML email!</title></head><body><p>This is HTML!</p></body</html> and the plaintext message should be This is plaintext. HTML代码应为<html><head><title>HTML email!</title></head><body><p>This is HTML!</p></body</html>和纯文本消息应该This is plaintext.

What would be the arguments to mail() to accomplish this? 要实现此目的, mail()的参数是什么? I know a lot of it deals with changing the header in some crazy way. 我知道很多事情都以某种疯狂的方式来处理标题。

Thanks so much! 非常感谢!

Use something like SwiftMailer instead, as it has nice things like header injection prevention. 请改用SwiftMailer之类的东西,因为它具有防止标头注入的功能。 With that in mind, yes, you have to set custom headers and use a multi-part body to achieve what you want: 考虑到这一点,是的,您必须设置自定义标头并使用多部分主体来实现所需的功能:

/***************************************************************
 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;

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

This is a lot of work. 这是很多工作。 Which, once again, is why I recommend having a library that can handle all of this for you, plus other features. 再次,这就是为什么我建议拥有一个可以为您处理所有这些问题的库以及其他功能的原因。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM