2009-12-07 185 views

回答

7

只需用一個逗號分隔的地址列表作爲第一個參數:

mail("[email protected], [email protected]", $subject, $message, $from); 

事實上,你可以使用任何支持的格式由RFC2822,包括:

$to = "Someone <[email protected]>, Tom <[email protected]>"; 
mail($to, $subject, $message, $from); 
+0

謝謝,本·詹姆斯。 我不知道RFC2822是什麼,但我會閱讀它。 – Newb 2009-12-07 13:29:24

3

都能跟得上你不能做到這一點。根據PHP手冊中的定義,to參數可以是:

接收方或郵件的接收方。

此字符串的格式必須 符合»RFC 2822的一些例子 是:

* [email protected] 
* [email protected], [email protected] 
* User <[email protected]> 
* User <[email protected]>, Another User <[email protected]> 

這意味着:

mail("[email protected], [email protected]", "Subject: $subject", 
    $message, "From: $email"); 

會更合適。

參見:http://php.net/manual/en/function.mail.php

1

你只需要CSV(逗號分隔值)包含在一個字符串中的電子郵件地址列表。

mail("[email protected], [email protected]", $subject, $message, $email); 

沿着同樣的道理,你在函數參數上有一些小錯誤。

+0

實際上CSV是一個相當明確的標準,這不符合。例如,在CSV中,逗號後面的空格將成爲下一個字段的一部分。 – 2009-12-07 13:22:41

0

你也可以這樣做:

 
$to = array(); 
$to[] = '[email protected]'; 
$to[] = '[email protected]'; 

// do this, very simple, no looping, but will usually show all users who was emailed. 
mail(implode(',',$to), $subject, $message, $from); 

// or do this which will only show the user their own email in the to: field on the raw email text. 
foreach($to as $_) 
{ 
    mail($_, $subject, $message, $from); 
}