2009-12-07 186 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); 
}