0

代码如下。我希望它分隔 [From: xxxxxx] 部分,以便正文/消息的其余部分出现在不同的行上。

<?php

    $name = $_POST["name"];
    $email = $_POST["email"];
    $message = $_POST["message"];

    $recipient = "me@christianselig.com";
    $subject = "Message From Website";
    $body = "[From: " . $name . "]\n\n" . $message;
    $headers = "From: " . $email . "\r\n";
    $headers .= "Content-type: text/html; charset=UTF-8" . "\r\n";

    $success = mail($recipient, $subject, $body, $headers);

    echo $success;

?>
4

1 回答 1

2

您应该使用 HTML 标签<br />而不是 \n

像这样:

$body = "[From: " . $name . "]<br /><br />" . $message;

以及使用该mail()功能的建议:

if( mail($recipient, $subject, $body, $headers) )
    echo 'Success';
else
    echo 'Fail';

编辑 1

当您尝试以纯文本形式发送时,您应该使用\r\n,这是纯文本中换行的转义序列。例子:

$formcontent="[From: " . $name . "]\r\n\r\n" . $message;
于 2012-10-07T02:19:22.233 回答