0

I normally mail single user on php but what I dont know if its possible to fetch all emails from the users table and bundle it in one variable ($to) and then mail it together with

mail($to, $subject, $message, $headers);

Can anyone help me with the syntax on how to mail multiple users? I am new to php and mysqli. Thanks.

ellooku
  • 161
  • 2
  • 11
  • 2
    Example #4: http://www.php.net/manual/en/function.mail.php – David Mar 17 '14 at 19:25
  • You can try yourself : )) But that's not advisable, rely on some queue /existing service like Mailchimp for instance. – moonwave99 Mar 17 '14 at 19:30
  • It depends on your specific use case, but I'd generally advise against this as well, for two reasons: 1) Most mail servers limit the number of recipients that you can send to with a single message. 2) If you send a message in this manner, each recipient will be able to see the email addresses of all the other recipients. – Alex Howansky Mar 17 '14 at 19:54
  • Nice taught alex. Thanks – ellooku Mar 17 '14 at 20:25

1 Answers1

1

PHP send mail to multiple email addresses

$recipients = array(
  "youremailaddress@yourdomain.com",
  // more emails
);

$email_to = implode(',', $recipients); // your email address
$email_subject = "Contact Form Message"; // email subject line
$thankyou = "thankyou.htm"; // thank you page

mail($email_to, $email_subject, $thankyou);

Note that you can use a custom message in place of $thankyou if you just want a standard message instead of html.

Community
  • 1
  • 1
Tricky12
  • 6,752
  • 1
  • 27
  • 35