I am trying to send multiple emails via a for loop so I don't have to worry about hiding all the other emails but every time I test it, It keeps send the the last email in the array and total misses the first and last names.
Here is how the each array element reads "firstname lastname <email>," (the quotes are just to seperate it from the sentence)
Here's the code:
$to = $_POST['to'];
$from = "$sender";
$subject = $_POST['subject'];
$message = $_POST['message'];
$i = "";
if($to == "Mass email"){
$sql =("SELECT * FROM `$table5`");
$res = mysqli_query($con5, $sql) or die (mysqli_error());
$adresses = [];
while($row = mysqli_fetch_assoc($res)){
$email = $row['firstname'] . " " . $row['lastname'] . " <" . $row['email'] . ">";
$adresses[] = $email;
}
foreach($adresses as $value){
if(empty($_FILES['file'])){
$mbox = imap_open("{mail.server.com:993/novalidate-cert/imap/ssl}", "$eun", "$epw");
$sent_mass_1 = mail($value, $subject, $message, "From: $from");
if($sent_mass_1){
imap_append($mbox, "{mail.server.com:993/novalidate-cert/imap/ssl}INBOX.Sent"
, "Date: $date
"
. "To: " . $value . "
"
. "From: $from
"
. "Subject: $subject
"
. "
"
. "$message
"
);
}
}
}
I'm just getting started in php arrays and I have a lot more to learn