I need help with this code to send email to users when they forget to activate their accounts. The code is able to print the list of users with accounts not activated but only sends email to one user. Thank you!
function joinDateFilter(){
$query = mysql_query("SELECT * FROM oc_accounts WHERE active = 2");
$mail_to = "";
while ($row = mysql_fetch_array($query)){
echo $row['name']." - ".$row['email']." - ".$row['createdDate']."\n";
$mail_to = $row['email']."";
$account_name = $row['name']."";
$created_date = $row['createdDate']."";
$token = $row['activationToken']."";
}
if (!empty($mail_to)){
sendEmail($mail_to,$account_name,$created_date,$token);
}
}
function sendEmail($mail_to,$account_name,$created_date,$token) {
$url.='http://mywebsite.com/registrar-uma-nova-conta.htm?account='.$mail_to.'&token='.$token.'&action=confirm';
$from = "[email protected]";
$message="<img src='http://www.mywebsite.com/images/logo.png'><br><br>
Prezado ".$account_name.',<br><br>
Seu cadastro criado em '.$created_date.' ainda não foi confirmado.<br><br>
Clique no link abaixo para confirmar sua conta e começar a anunciar<br>
seus produtos.<br><br>
<a href="'.$url.'">confirmar conta</a><br><br>
http://mywebsite.com/registrar-uma-nova-conta.htm?account='.$mail_to.'&token='.$token.'&action=confirm<br><br>
Thanks!';
$headers = 'From: '.$from."\r\n" .
'Reply-To:'.$_POST['email']."\r\n" .
"Content-Type: text/html; charset=iso-8859-1\n".
'X-Mailer: PHP/' . phpversion();
mail($mail_to,"Ative sua conta! - My website",$message,$headers);
}
If I understand correctly, this code is supposed to send an email to multiple addresses in your database. In that case, simply move the if statement into the while loop:
Also, check out https://www.php.net/mysqli You should change your mysql commands to mysqli.