PHP邮件中的换行符():\ n,\\ n和\ r \ n不工作
问题描述:
这是在LAMP服务器上。PHP邮件中的换行符(): n,\ n和 r n不工作
我在网上找到的所有答案都表明上面的其中一个应该可以工作,但我无法得到它的工作。
我的代码是:
$to = $email_to;
$subject = 'Website Form';
$message = 'From: ' . $name .
' \r\n Date: ' . $date .
' \r\nText: ' . $text .
'\r\n Use on Presentations?: ' . $presentations .
'\r\n Use on Websites?: ' . $website .
'\r\n Use on Case Studies?: ' . $casestudy;
$headers = 'From: [email protected]' . "\r\n" .
'Reply-To: [email protected]' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
会有人知道我做了什么错?
答
您使用单引号,如果你想使用\ n或\ r你必须把它们用双引号,如:
$value = "here is some text, and a $variable, and a line end\r\n";
我做了很多的PHP邮件的东西,\ r \ n必须在“...”或它不是作为一个逃脱的字符执行,而是作为一个文字。
即:
echo ".\n.";
# is this:
.
.
#but
echo '.\n'.;
#is this:
.\n.
仅此而已。
答
为此,您可以设置标题,如$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
,然后用户<br />
代替\n
。
答
你为什么要使用\r\n
,使用<BR>
$message = 'From: ' . $name .
' <BR> Date: ' . $date .
' <BR>Text: ' . $text .
' <BR>Use on Presentations?: ' . $presentations .
' <BR>Use on Websites?: ' . $website .
' <BR>Use on Case Studies?: ' . $casestudy;
不能用于标题或消息? –