2010-04-08 52 views
3

我使用PHP的郵件功能發送郵件。 它的工作原理與所有電子郵件客戶端顯示的空白字段一樣。 這裏就是我如何使用功能:使用PHP的郵件發送的郵件()有空白字段

mail('[email protected]', 'Example subject', $msg, 
     implode('\r\n', array('Content-Type: text/html; charset=UTF-8', 'From: [email protected]'))); 

正如我所說的一切工作,除了從外地當郵件到達所有空白的罰款。 任何想法爲什麼發生這種情況?

+0

這種鱈魚e會產生一個解析錯誤。你可以展示一個真實的代碼嗎? – 2010-04-08 06:57:10

+0

啊對不起,不得不編輯一下。祕密的東西你知道。) 現在應該工作 – Nikkeloodeni 2010-04-08 06:58:26

+0

那麼,這個編輯的代碼的結果是什麼? – 2010-04-08 07:02:39

回答

1

您在「Content-Type」之前缺少一個報價,並且可能錯誤日誌記錄轉向了下方,因此它忽略了問題並且無法解析您的代碼。

應該是:

mail('[email protected]', "Example subject", $msg, 
     implode("\r\n", array('Content-Type: text/html; charset=UTF-8', 'From: [email protected]'))); 
+0

正確絕對正確 – 2010-04-08 06:57:50

2

試試這個

<?php 
$to  = '[email protected]'; 
$subject = 'the subject'; 
$message = 'hello'; 
$headers = 'From: [email protected]' . "\r\n" . 
    'Reply-To: [email protected]' . "\r\n" . 
    'X-Mailer: PHP/' . phpversion(); 

mail($to, $subject, $message, $headers); 
?> 

對你的想法 入住這就是你得到

<?php 
    $implode =implode("\r\n", array('Content-Type: text/html; charset=UTF-8', 'From: [email protected]')); 

    echo "<pre>"; 
    print_r($implode); 
    ?> 
+0

這確實有效,但我仍然無法得到它爲什麼我的版本不包括From頭?我也嘗試添加X-Mailer和Reply-To標題,但在發送的電子郵件中仍然沒有發件人字段。 – Nikkeloodeni 2010-04-08 07:00:57

+0

試試做郵件功能的implode並將它保存爲一個變量,然後我們在郵件函數中使用這個變量 – 2010-04-08 07:05:16

+0

在我的更新回答中找到您的代碼的方向 – 2010-04-08 07:11:16