I am trying to send bulk mail. And It worked but the problem is when I am checking on Gmail this shows. I can use Bcc and solve this issue but I want to for learning purposes.
------------------------------------------
from: example <example@gmail.com>
to: example1@gmail.com,
example2@gmail.com,
example2@gmail.com
date: Dec 19, 2021, 1:18 AM
subject: Testing Mail
mailed-by: example
signed-by: example
security: Standard encryption (TLS) Learn more
---------------------------------------------
In the recipient why all subscriber's mail is showing in "to". Please help me to fix it. I want to show specific subscriber mail.
Here is my code
<?php
if(isset($_POST['sendmail'])) {
$status=1;
$sql = "SELECT * FROM subscribers WHERE status=? ORDER BY id ";
$stmt = $conn2->prepare($sql);
$stmt->bind_param("s", $status);
$stmt->execute();
$result15 = $stmt->get_result();
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.example.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = EMAIL; // SMTP username
$mail->Password = PASS; // SMTP password
$mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465; // TCP port to connect to
if (mysqli_num_rows($result15)>0) {
while ($row = mysqli_fetch_array($result15)) {
$mail->AddAddress($row['email']); // Add a recipient
}
}
$mail->setFrom(EMAIL, 'example');
//$mail->addReplyTo(NOREPLY);
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $_POST['subject'];
$mail->Body = '<div style="border:2px solid red;">This is the HTML message body <b>in bold!</b></div>';
$mail->AltBody = $_POST['message'];
if (!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
}
?>