PHP断线"。\ n"没有在电子邮件正文中工作。线条消失了

时间:2018-01-14 16:07:00

标签: php html email variables line-breaks

如何在fscanf$sender_name之后突破线?现在它只显示$sender_number作为输出,但当我删除" $sender_name"他们都在一条线上。

\n

整个PHP代码

    $body .= chunk_split(base64_encode($sender_name."\n\r"));
    $body .= chunk_split(base64_encode($sender_number."\n\r"));
    $body .= chunk_split(base64_encode($sender_message."\n\r"));

2 个答案:

答案 0 :(得分:2)

你是base64编码行结尾以及

所以实际输出不会有\ n \ r 试试这个:

$body = $sender_name. "\n";
$body = $sender_number. "\n";
$body = $sender_message. "\n";

编辑: 鉴于您的代码:

.=

在这些行中,您不会附加字符串,而是为其指定新值;使用HashSet<string>代替赋值运算符

答案 1 :(得分:2)

你也是encondig“\ n \ r”,请务必将换行符放在最后,

  $body .= chunk_split(base64_encode($sender_name)) . PHP_EOL;
  $body .= chunk_split(base64_encode($sender_number)) . PHP_EOL;
  $body .= chunk_split(base64_encode($sender_message)) . PHP_EOL;

如果您使用PHP_EOL发送电子邮件作为html替换<br />,请执行以下操作:

  $body .= chunk_split(base64_encode($sender_name)) . "<br />";
  $body .= chunk_split(base64_encode($sender_number)) . "<br />";
  $body .= chunk_split(base64_encode($sender_message)) . "<br />";