开发者

PHP mail() specific question

开发者 https://www.devze.com 2023-03-05 18:08 出处:网络
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; a mixed message email.

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; 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.

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.

What would be the arguments to mail() to accomplish this? I know a lot of it deals with changing the header in some crazy way.

Thanks so mu开发者_如何学Pythonch!


Use something like SwiftMailer instead, as it has nice things like header injection prevention. 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

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.


Everything is here (Example #4): http://php.net/manual/en/function.mail.php

0

精彩评论

暂无评论...
验证码 换一张
取 消