2013-04-24 35 views
2

發送電子郵件我無法設置頁眉在PHP從地址我已經嘗試了所有可能的值:無法設置頭在PHP和的cPanel

下面的代碼是正確的,但代碼不附接到頭。

它顯示此爲默認值,但不會更改。

From : webhost:[email protected] 

這是cpanel的問題嗎?

請幫助我,真的很感謝幫助。

在此先感謝。

<?php 

$name = $_REQUEST['name']; 
$email = $_REQUEST['email']; 
$phone = $_REQUEST['contact']; 

$subject = "feedback"; 
$question = $_REQUEST['question']; 


$body = "<html> 
<head> 

</html>"; 
$mime_boundary = "<<<--==+X[".md5(time())."]\r\n\r\n"; 
$headers = "MIME-Version: 1.0"."\r\n" ."Content-Type:text/html;"."\r\n"; 
$headers .= 'From:'.$email. "\r\n"; 


$to ='[email protected]'; 
mail($to,$subject,$body,$headers); 
echo "<script>alert(' message sent.');</script>"; 

?> 

也試過:

<?php 
$headers = array(); 
$headers[] = "MIME-Version: 1.0"; 
$headers[] = "Content-type: text/plain; charset=iso-8859-1"; 
$headers[] = "From: Sender Name <[email protected]>"; 
    $headers[] = "Reply-To: Recipient Name <[email protected]>"; 
$headers[] = "Subject: {$subject}"; 
$headers[] = "X-Mailer: PHP/".phpversion(); 

mail($to, $subject, $email, implode("\r\n", $headers)); 
?> 

只有這樣工作的:

$to ='[email protected]'; 
$subject="subject"; 
$body="body"; 
    $mime_boundary = "<<<--==+X[".md5(time())."]\r\n\r\n"; 
    $headers = "MIME-Version: 1.0"."\r\n" ."Content-Type:text/html;"."\r\n"; 
    mail($to,$subject,$body,$headers); 
+0

爲什麼不嘗試發送簡單的郵件? – 2013-04-24 20:36:29

+0

上面添加的代碼,如果標題有回覆,從那我可以迴應,因此用戶也可以不響應/迴應,因爲cPanel虛擬主機帳戶名稱將不會有一個電子郵件帳戶,因此交付將失敗。我想用我自己的ID替換標題這是所有! – 2013-04-24 20:43:52

回答

2

試試這個:

$to = '[email protected]'; 

$subject = "Email from me by: John"; 
$body = "my body"; 
$headers = "From: "."[email protected]"."\r\n" . 
"Reply-To: "."[email protected]"."\r\n". 
"X-Mailer: php"; 
$sent=mail($to, $subject, $body, $headers); 

if ($sent) { 

echo "good!"; 

} else { 
echo("<p>Message delivery failed...</p>"); 
} 
+0

消息傳遞失敗...不知道爲什麼? – 2013-04-24 20:58:10

+0

然後確定問題是在服務器上,我給你一個工作生產代碼,也許「郵件」沒有安裝在服務器上 – Dima 2013-04-24 21:03:33

+0

$ to ='[email protected]'; $ subject =「subject」; $ body =「body」; $ mime_boundary =「<<< - == + X [」。md5(time())。「] \ r \ n \ r \ n」; $ headers =「MIME-Version:1.0」。「\ r \ n」。「Content-Type:text/html;」。「\ r \ n」; 郵件($ to,$ subject,$ body,$ headers);這是工作,所以郵件的作品。 – 2013-04-24 21:10:20