Result Required : send mail to individual student. Result getting : It send 3 mail to test1 user. In first mail test1 get his mail id in "TO". In second mail test1 get his mail id & test2 mail id in "TO" In third mail test1 get his mail id & test2 & test3 mail id in "TO"
$d=date('Y-m-d');
$qu="select * from student";
$res=mysqli_query($con,$qu);
if($res && mysqli_num_rows($res)>0)
{
while($row=mysqli_fetch_assoc($res))
{
$e1=$row["stu_name"];
$e2=$row["mailid"];
$e3=$row["d_date"];
if($e3 == $d)
{
try
{
//Server settings
$mail->SMTPDebug = 2;
$mail->isSMTP();
$mail->Host = 'xys.xyz.com';
$mail->SMTPAuth = true;
$mail->Username = 'xyz@xyz.com';
$mail->Password = 'abc';
$mail->Port = 25;
$mail->setFrom('xyz@xyz.com', 'test');
$mail->addAddress($e2);
$mail->isHTML(true);
$mail->Subject = "Test Mail";
$mail->Body = "Dear ".$e1.",</br>hello";
$mail->send();
echo 'Message has been sent';
}
catch (Exception $e)
{
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
}
}
}
DATABASE :
S_no stu_name mailid d_date
1 test1 test1@gmail.com 2021-02-02
2 Test2 test2@gmail.com 2021-02-02
3 Test3 test3@gmail.com 2021-02-02