发送电子邮件与php纯文本和HTML [英] Sending an email with php plain text and html
本文介绍了发送电子邮件与php纯文本和HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下电子邮件标题:
I have the following email header:
$random_hash = md5(date('r', time()));
$headers = array ('From' => $from,
'To' => $to,
'Return-Path' => 'info@example.com',
'Subject' => $subject,
'Content-Type'=>'multipart/alternative');
我想在一封电子邮件中发送两个版本的电子邮件。一个文本和一个html。
I want to send two versions of email in one email. One text and one html.
所以我这样做:
ob_start(); ?>
--PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Copy and paste: http://example.com/app_dl.php?app_id=<?php echo $_GET[app_id]; ?> to download your $app_name app \r\n
Want to get tons more hot apps for free! anywhere anytime? Download our app on http://example.com \r\n
example.com team;
--PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
<p><a href='http://example.com/app_dl.php?app_id=<?php echo $_GET[app_id]; ?>'>Click Here</a> to download your <?php echo $app_name_app; ?></p>
<p>Want to get tons more hot apps for free! anywhere anytime? Download our app on <a href='http://example.com'>example.com</a></p>
<br/>
<p>example.com team</p>";
<?php
$bodyHTML =ob_get_clean();
但它似乎不是很好,但我不知道为什么!?!?
But it doesnt seem to work well..and I wonder why!?!?
推荐答案
为了创建一个 multipart / alternative
消息,你需要指定一个边界
,并将每个部分分隔开边界。一个好的边界字符串将是不太可能在消息部分本身中发生的东西,例如由 sha1生成的随机字符串uniqid())
。例如:
In order to create a multipart/alternative
message, you need to specify a boundary
and separate each part by that boundary. A good boundary string would be something that is highly unlikely to occur in the message part itself, such as a random string generated by sha1(uniqid())
. For example:
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary=c4d5d00c4725d9ed0b3c8b
--c4d5d00c4725d9ed0b3c8b
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
part1
--c4d5d00c4725d9ed0b3c8b
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
<b>part2</b>
--c4d5d00c4725d9ed0b3c8b--
这是在 RFC 2046,第5.1.4节。
这篇关于发送电子邮件与php纯文本和HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文