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.
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); } ?>
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With