I have an array of emails and want to send an email for each entry in the array but currently it only sends it to the first address. I have looked around and can’t see what I am doing wrong.
//This is the array
$emails = array($teamleademail, $coleademail, $sponsoremail, $facilitatoremail, $cisupportemail);
//Now the foreach statment
foreach ($emails as $value) {
//pulls in email sending code
require_once ("Mail.php");
//variables required to send the email
$from = "Scope Sheet Process Database (no reply)<scopesheetprocess@goodrich.com>";
//Make the $to variable that of the email in the array
$to = "$value";
$subject = "Scope Sheet $scopesheetid Closed";
$body = "Scope Sheet $scopesheetid has been closed and can no longer be edited.";
//send email code
require_once ("sendemail.php");
}
I am using pear php to send the email because of IT issues but that shouldn’t matter since it should be running the scripts each time and sending separate emails.
The problem is this line:
…should just be
As it is, it will only be included on the first iteration of the loop, hence only the first email is sent.
This on its own may not fix your problem – if it doesn’t we’ll need to see the code in
sendemail.php.