I have an issue with my code, I'am trying to send multiple mails at once to different users but it only sends the mail to the first mail in my mails list.
Can anyone help me find where the problem is located?
function send_mails($filename, $from){
$infos = combine_mails_to_passwords($filename);
$headers = "MIME-Version: 1.0" . "
";
$headers .= "Content-Type: text/html; charset=UTF-8
";
$headers .= "X-Mailer: PHP". phpversion() ."
" ;
$headers .= "From: '$from'" . "
";
foreach($infos as $key => $info){
$to = $info;
$subject = "TEST Mail";
$message = "<h2 style='font-size:18px;'>
Voici vos identifiants pour passer l'évaluation</h2>
<div style='text-align:center;'>
<table><tr><td><u>Login: </u></td> <td><b> ".$_SESSION['login']."</b><td></tr><br/>
<tr><td><u>Votre Mot de Passe: </u></td> <td><b> ".$key."</b></td></tr></table></div>";
$from = "From: Company Name <TEST>";
$ok = mail($to,$subject,$message,$headers);
return $ok;
}
}
if(isset($_POST['send-submit'])){
if (!empty($_FILES['fileToUpload']) && $_FILES['fileToUpload']['name']!=''){
$file_path = $_FILES['fileToUpload']['tmp_name'];
$from = $_POST['from'];
if($from!=""){
if($_FILES['fileToUpload']['type'] != 'text/plain'){
$error = "The file is not a text file!";
}
else if(count_mails($file_path)==0){
$error = "The file is empty!";
}
else{
if(send_mails($file_path, checkInput($from))){
$good = "Mails sent!";
}
else{
$error = "Connexion Problem!";
}
}
}
else{
$error = "Please enter the email of the sender!";
}
}
else{
$error = "You did not import the emails file!";
}
}
Note: The mails are uploaded from a text file. Thank you!