Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php mail multiple recepients

Tags:

php

email

I am able to send email to one email id by defining the id in the mailer, but i am not able to understand how to send to multiple recepients when an user types "mssage and email id's" in a form. Ex - I am showing a form with two text areas - one for email id's and one for custom message. So when they click send, i want to take the email id's from that text area and send that message to those ids. I am yet to figure out how to comma/space seperate the emailds but will try it in google search.

thanks

like image 288
JDesigns Avatar asked Aug 01 '26 21:08

JDesigns


2 Answers

The documentation of the to parameter for the mail() function states:

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]>

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

Update:

I've come across this great tutorial on sending mail with PHP: http://articles.sitepoint.com/article/advanced-email-php

like image 111
George Marian Avatar answered Aug 03 '26 12:08

George Marian


It's far easier to use something like PHPMailer (free, easy to install, easy to use) if you have to do anything even "moderately" complicated, like multiple recipients for an email. It'll hide all the ugly details for you behind a nice interface. Instead of worrying about header syntaxes and whatnot, you just do something like:

$mail = new PHPMailer();
$mail->AddAddress('[email protected]');
$mail->AddAddress('[email protected]');
etc...
like image 33
Marc B Avatar answered Aug 03 '26 11:08

Marc B



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!