问题
i have to send mail with function mail() of PHP. I have to insert Reply-To header but it not work:
<?php
$body = "<html>\n";
$body .= "<body style=\"font-family:Verdana, Verdana, Geneva, sans-serif; font-size:12px; color:#666666;\">\n";
$body = $message;
$body .= "</body>\n";
$body .= "</html>\n";
$headers = "From: My site<noreply@example.com>\r\n";
$headers .= "Reply-To: info@example.com\r\n";
$headers .= "Return-Path: info@example.com\r\n";
$headers .= "X-Mailer: Drupal\n";
$headers .= 'MIME-Version: 1.0' . "\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
return mail($recipient, $subject, $message, $headers); ?>
In this example of php.net there is $headers .= "Reply-To: info@example.com\r\n"; but if copy and paste this and then send mail the Reply-To header there is not. If insert other header like From, CC, Bcc these there are correctly in my HTML mail, only Reply-To header there is not. I have try like "Reply-to", "Reply to", "Reply To", "Reply" etc but it not work. I have use Php 5.4 can help me?
回答1:
Try this.
add parameter for recipient, subject, and message.
then at this line " return mail($recipient, $subject, $message, $headers); "
replace the $message into $body.
look like this
<?php
$recipient = "jack@example.com";
$subject = "test subject";
$message = "test message";
$body = "<html>\n";
$body .= "<body style=\"font-family:Verdana, Verdana, Geneva, sans-serif; font-size:12px; color:#666666;\">\n";
$body = $message;
$body .= "</body>\n";
$body .= "</html>\n";
$headers = "From: My site<noreply@example.com>\r\n";
$headers .= "Reply-To: info@example.com\r\n";
$headers .= "Return-Path: info@example.com\r\n";
$headers .= "X-Mailer: Drupal\n";
$headers .= 'MIME-Version: 1.0' . "\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$result = mail($recipient, $subject, $body, $headers);
var_dump($result);
?>
hope it will help you
来源:https://stackoverflow.com/questions/11610729/header-function-mail-php