开发者

php email function

One recipient: someone@example.com

mail("someone@example.com", "Subject: $subject",
    $message, "From: $email" );

If I want two recipients, can I do this:

somone@example.com and tom@php.com

   mail("someone@example.com", "tom@php.com", "Subjec开发者_JAVA技巧t: $subject", 
        $message, "From: $email" );


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

mail("someone@example.com, tom@php.com", $subject, $message, $from);

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

$to = "Someone <someone@example.com>, Tom <tom@php.com>";
mail($to, $subject, $message, $from);


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:

* user@example.com
* user@example.com, anotheruser@example.com
* User <user@example.com>
* User <user@example.com>, Another User <anotheruser@example.com>

which means:

mail("someone@example.com, tom@php.com", "Subject: $subject", 
    $message, "From: $email" );

would be more appropriate.

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


Multiple email addresses go in as a comma separated list:

mail("email1@domain.ext, email2@domain.ext" ...


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

mail("someone@example.com, tom@php.com", $subject, $message, $email);

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


Try this :

 mail("someone@example.com, tom@php.com", "Subject: $subject", 
        $message, "From: $email" );


you could also do:

$to = array();
$to[] = 'someone@example.com';
$to[] = 'tom@php.com';

// 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);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜