使用php,并且使用此代码我以纯文本形式收到电子邮件,我错过了什么吗? 因为我需要发送可能包含链接的格式化电子邮件。
$to = "receiver@test.com";
$subject = "Password Recovery";
$body = '
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Birthday Reminders for August</title>
</head>
<body>
<p>Here are the birthdays upcoming in August!</p>
<table>
<tr>
<th>Person</th><th>Day</th><th>Month</th><th>Year</th>
</tr>
<tr>
<td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
</tr>
<tr>
<td>Sally</td><td>17th</td><td>August</td><td>1973</td>
</tr>
</table>
</body>
</html>
';
$headers = 'MIME-Version: 1.0' . "'r'n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "'r'n";
$headers = "From: info@test.net'r'n"."X-Mailer: php";
if (mail($to, $subject, $body, $headers))
echo "Password recovery instructions been sent to your email<br>";
您已经重新设置了标头:
$headers = 'MIME-Version: 1.0' . "'r'n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "'r'n";
$headers = "From: info@test.net'r'n"."X-Mailer: php";
你在最后一行中缺少一个点,它覆盖了前两行:
$headers = 'MIME-Version: 1.0' . "'r'n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "'r'n";
$headers .= "From: info@test.net'r'n"."X-Mailer: php";
看看这个例子,这足以用 php 发送邮件:
<?php
//change this to your email.
$to = "abc@gmail.com";
$from = "Example@example.com";
$subject = "Hello! This is HTML email";
//begin of HTML message
$message ="
<html>
<body>
<p style='"text-align:center;height:100px;background-color:#abc;border:1px solid #456;border-radius:3px;padding:10px;'">
<b>I am receiving HTML email</b>
<br/><br/><br/><a style='"text-decoration:none;color:#246;'" href='"www.example.com'">example</a>
</p>
<br/><br/>Now you Can send HTML Email
</body>
</html>";
//end of message
$headers = "From: $from'r'n";
$headers .= "Content-type: text/html'r'n";
//options to send to cc+bcc
//$headers .= "Cc: [email]maa@p-i-s.cXom[/email]";
//$headers .= "Bcc: [email]email@maaking.cXom[/email]";
// now lets send the email.
mail($to, $subject, $message, $headers);
echo "Message has been sent....!";
?>
我发现特定的邮件服务器存在同样的问题,就我而言,解决方案是将"'"而不是"''r'"设置为标题的行尾。
尽管您的问题似乎是由重新分配给$headers引起的,但我遇到了类似的问题,并发现原因是双行结尾"/r/n"。某些邮件应用程序(如 Bluemail)在读取双行结尾后启动邮件正文(有效地结束标题)。
就我而言,它是通过更改以下内容来解决的:
$headers = 'MIME-Version: 1.0' . "'r'n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "'r'n";
$headers .= "From: info@test.net'r'n"."X-Mailer: php";
对此:
$headers = 'MIME-Version: 1.0' . "'n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "'n";
$headers = "From: info@test.net'n"."X-Mailer: php";