2012-07-23 98 views
1

我必須使用PHP的函數mail()發送郵件。 我要插入的Reply-To頭,但它不工作:header function mail()php

<?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<[email protected]>\r\n"; 
    $headers .= "Reply-To: [email protected]\r\n"; 
    $headers .= "Return-Path: [email protected]\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); ?> 

在php.net的這個例子中有$標題= 「回覆:[email protected] \ r \ n」。但如果複製並粘貼,然後發送郵件回覆到頭沒有。如果插入其他標題,如From,CC,Bcc,則這些標題在我的HTML郵件中正確顯示,但只有Reply-To標題沒有。 我試着像「回覆」,「回覆」,「回覆」,「回覆」等,但它不起作用。 我有使用PHP 5.4可以幫助我嗎?

回答

3

試試這個。

爲收件人,主題和消息添加參數。

然後在這行 「返回郵件($收件人,$主題,$消息,$頭);」

更換$消息到$體。

這個樣子的

<?php 

$recipient = "[email protected]"; 
$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<[email protected]>\r\n"; 
$headers .= "Reply-To: [email protected]\r\n"; 
$headers .= "Return-Path: [email protected]\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); 

?> 

希望它會幫助你

+0

感謝的答案,但問題是沒有參數... INFACT我有inizialize參數收件人,主題和消息,並正確地發送郵件。 當我打開我在字段中看到的郵件從「My site <[email protected]>」(如本例中),並且如果添加$ headers。=「Cc:[email protected] \ r \ n」 $ headers =「From:我的網站<[email protected]> \ r \ n」;在代碼中,當我打開郵件時,我在字段「我的網站<[email protected]>」和字段Cc [email protected]中看到該郵件。只有回覆標題沒有。如何正確地查看郵件中的字段Reply-To? – user1487934 2012-07-23 10:51:27

+0

我明白了..但是,您是否嘗試將上面給出的代碼集成到您的代碼中?我測試了我的代碼並顯示了答覆。讓我知道.. – Jack 2012-07-26 09:45:16