2016-11-07 120 views
0

當使用PHP的mail()功能,我收到的電子郵件到兩個帳戶時「到」參數設置爲:爲什麼PHP郵件不能發送給多個收件人?

"[email protected],[email protected]" 

,但是當我換他們圓:

"[email protected],[email protected]" 

的電子郵件時到[email protected]但不是[email protected]。如果指定爲CC或BCC標題,它也不會收到電子郵件。

有人可以提出爲什麼這可能是這種情況?直到幾個星期前,它工作良好。據我所知,我的服務器上沒有任何變化,雖然它是共享主機,所以它可能會有。

注意事項:無論順序如何,mail()函數始終返回trueexample1.com也是發送服務器。

我的代碼如下:

$from = '[email protected]'; 

$headers = ''; 
$headers .= 'From: My Site <' . $from . ">\r\n" . 
      'Reply-To: ' . $_POST["Email"] . "\r\n" . 
      'X-Mailer: PHP/' . phpversion(); 

$body = 'Message goes here'; 

$to = '[email protected],[email protected]'; // will not send to [email protected], though will if the addresses are swapped 

if (mail($to, 'Subject goes here', $body, $headers, '-f ' . $from)) { 
    $url = "/contact/?message=sent"; 
} else { 
    $url = "/contact/?message=failed"; 
} 

header("Location: $url"); 
+1

調試郵件傳遞就像給貓洗澡一樣。但如果你有權訪問服務器郵件日誌,那就是我要開始的地方。 – nogad

+0

是否確定電子郵件沒有被髮送,而是被垃圾郵件過濾器攔截? –

+0

查看PHP手冊,我注意到這個例子在逗號後有一個空格。'$ to ='[email protected],[email protected]';' 您也可以使用您的標題部分添加一個CC '$ headers。='抄送:[email protected]'。 「\ r \ n」;' –

回答

0

縱觀PHP手冊,我看到的例子有逗號後的空間.. 嘗試

$to = '[email protected], [email protected]'; 

你也可以用你的頭部分添加一個CC

$headers .= 'Cc: [email protected]' . "\r\n"; 
+0

正如我的問題所指出的,CC(非BCC)頭也不工作。我用逗號後面的空格試過,但那也不起作用。謝謝您的好意。 – b4tch

相關問題