header function mail() php

人盡茶涼 提交于 2019-12-13 02:28:17

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!