0
// Assign contact info
    $name = stripcslashes($_POST['name']);
    $emailAddr = stripcslashes($_POST['email']);
    $issue = stripcslashes($_POST['issue']);
    $comment = stripcslashes($_POST['message']);
    $subject = stripcslashes($_POST['subject']);    

// Set headers
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$headers = "From: $name <$emailAddr>";
$headers .= "\r\n";
$headers .= "Reply-To: $emailAddr"; 


// Format message
$contactMessage =
"<div>
<p><strong>Name:</strong> $name <br/>
<strong>E-mail:</strong> $emailAddr <br/>

<p><strong>Message:</strong> $comment </p>

<p><strong>Sending IP:</strong> $_SERVER[REMOTE_ADDR]<br/>
<strong>Sent via:</strong> $_SERVER[HTTP_HOST]</p>
</div>";

// Send and check the message status
$response = (mail('myemail@myserver.com', $subject, $contactMessage, $headers) ) ? "success" : "failure" ;
$output = json_encode(array("response" => $response));

header('content-type: application/json; charset=utf-8');
echo($output);

`

上面的代码有什么问题?在我从部分更改标题后,我没有收到 html 电子邮件我只收到纯文本电子邮件

4

1 回答 1

3

改变

$headers = "From: $name <$emailAddr>";

$headers .= "From: $name <$emailAddr>"; // you forgot to concatenation previous headers.
于 2012-12-21T08:18:45.647 回答