'PHPMailer MySQL Send mail with database infos
i'm trying to send mail with database informations with PHPMailer. My request if very specific and i don't understand how to do what i want..
Basically i have a table in my database in which i have email adresses and other datas and i want to send these datas to only these specific email adresses
I tried first to select all my data, put it in a array and then select all the email adresses using a while loop but it would send every datas to every email adresses
Here's my SQL :
$sql = SELECT info1, info2, info3, info4, info5, entreprise.nom as entreprise_name, entreprise.mail_commercial as mail FROM table JOIN entreprise ON equipement.entreprise_id = entreprise.id WHERE info1 < DATE(NOW() - INTERVAL 6 MONTH) AND info1 IS NOT NULL or info2 < DATE(NOW() - INTERVAL 3 MONTH) AND info2 IS NOT NULL
$result = mysqli_query($conn, $sql);
And here's my PHPMailer :
$datas = array();
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)){
$datas[] = $row;
}
}
$body = "Hello ";
foreach ($datas as $data){
$mail->AddAddress($data['mail']);
$mail->Subject = "Test";
$body .= $data['info1'] . ' ';
$body .= $data['info2']. ' ';
$body .= $data['info3']. ' ';
$body .= $data['info4']. ' ';
$body .= $data['info5']. ' ';
$body .= $data['entreprise_name']. ' '."</br>";
}
$body .= "";
$mail->Body = $body;
$mail->send();
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
