views:

84

answers:

6

One recipient: [email protected]

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

If I want two recipients, can I do this:

[email protected] and [email protected]

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

Just use a comma-separated list of addresses as the first parameter:

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

In fact, you can use any format supported by RFC2822, including:

$to = "Someone <[email protected]>, Tom <[email protected]>";
mail($to, $subject, $message, $from);
Ben James
Thanks, Ben James.I have no idea what RFC2822 is, but I will be reading about it.
Newb
+2  A: 

Multiple email addresses go in as a comma separated list:

mail("[email protected], [email protected]" ...
Tim
+3  A: 

Nope you can't do that. As per defined in PHP's manual, the to parameter can be:

Receiver, or receivers of the mail.

The formatting of this string must comply with » RFC 2822. Some examples are:

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

which means:

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

would be more appropriate.

See: http://php.net/manual/en/function.mail.php

thephpdeveloper
+1  A: 

You simply need CSV (comma separated value) list of email addresses contained within a single string.

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

Along the same token you had a few minor mistakes with the function parameters.

cballou
Actually CSV is a fairly well defined standard that this does not comply with. For example, in CSV, the space after the comma would become part of the next field.
Ben James
+1  A: 

Try this :

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

you could also do:

$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);
}
krob