简单问题......
我看到有人告诉我在各个地方使用"\ r \n",其他人告诉我在同一个地方使用"\n".我确信一个是正确的,一个是错的.示例 - 设计mail()标头时:
教程#1:
//define the headers we want passed. Note that they are separated with \r\n
$headers = "From: webmaster@example.com\r\nReply-To: webmaster@example.com";
//add boundary string and mime type specification
$headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";
Run Code Online (Sandbox Code Playgroud)
教程#2(注意头参数):
mail($to, $subject, $body,
"From: " . $from . "\n" .
"bcc: " . $bcc . "\n" .
"MIME-Version: 1.0\n" .
"Content-Type: multipart/alternative;\n" .
" boundary=" . $mime_boundary_header)
Run Code Online (Sandbox Code Playgroud)
我很困惑,但显然它有点不同,因为有一个,我的标题工作,而另一个,他们有时只工作.
Yad*_*ada 23
\ r \n是Windows系统的行尾字符.
\n是UNIX系统的行尾字符.
这些字符是不可见的.根据我自己的经验\n通常也适用于Windows.
有些人更喜欢使用PHP_EOL常量而不是这些字符来实现平台之间的可移植性.
echo 'hi' . PHP_EOL;
echo "hi\n";
$headers = "From: webmaster@example.com" . PHP_EOL
. "Reply-To: webmaster@example.com";
Run Code Online (Sandbox Code Playgroud)
除了Yada的回答,这里还有一个解释性的博客文章:https://blog.codinghorror.com/the-great-newline-schism/
[更新2017-05-24:修正了链接]