1

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?

user1487934
  • 11
  • 1
  • 1
  • 4

1 Answers1

3

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

Jack
  • 96
  • 2
  • Thanks for answer but the problem is not parameters...infact i have inizialize parameter recipient, subject and message and send correctly the mail. When i open the mail i see in the field From "My site" (like in this example), and if add $headers.="Cc: test@test.it\r\n" after $headers = "From: My site\r\n"; in the code when i open the mail i see in the field From "My site" and in the field Cc test@test.it. Only the Reply-To header there is not. How can do for view correcly the field Reply-To in the mail? – user1487934 Jul 23 '12 at 10:51
  • I see.. But have you try to integrate the code I've given above to your code? I have tested my code and the reply to is showing. Let me know.. – Jack Jul 26 '12 at 09:45