Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP send mail to multiple email addresses

Tags:

forms

php

What code I should do change in this PHP script to send one email to more than 20 email addresses?

<?php  $email_to = "[email protected]"; // your email address $email_subject = "Contact Form Message"; // email subject line $thankyou = "thankyou.htm"; // thank you page  ?> 

Please give me an example. Thank you.

like image 692
rakib Avatar asked Dec 22 '10 04:12

rakib


People also ask

How can I send multiple emails at a time in PHP?

php $contacts = array( "[email protected]", "[email protected]", //....as many email address as you need ); foreach($contacts as $contact) { $to = $contact; $subject = 'the subject'; $message = 'hello'; mail($to, $subject, $message, $headers); } ?>

Can PHP be used to send emails?

PHP makes use of mail() function to send an email. This function requires three mandatory arguments that specify the recipient's email address, the subject of the the message and the actual message additionally there are other two optional parameters.


1 Answers

Fore readability sake in the code use an array and implode it to a comma separated string:-

$recipients = array(   "[email protected]",   // more emails ); $email_to = implode(',', $recipients); // your email address $email_subject = "Contact Form Message"; // email subject line $thankyou = "thankyou.htm"; // thank you page 
like image 116
prodigitalson Avatar answered Sep 20 '22 21:09

prodigitalson