I am using below code to send email to all users in the mysql database uing phpmailer. My problem is .. mail is not sending to all recipients but mail is sent to one or two recipients . Is there any problem in the code. Thanks
<?php
require_once('phpmailer/class.phpmailer.php');
error_reporting( E_ALL & ~E_DEPRECATED & ~E_NOTICE & ~E_STRICT );
$host="mysql.hostinger.in"; // Host name
$username="u831209167_user"; // Mysql username
$password="###"; // Mysql password
$db_name="u831209167_name"; // Database name
// Connect to server and select databse.
$con=mysql_connect($host,$username,$password) or die("Can't connect to database!");
mysql_select_db("u831209167_name");
$str="SELECT email FROM `notification` ";
$res=mysql_query($str,$con);
while($row=mysql_fetch_array($res))
{
$mail = new PHPMailer();
$mail->CharSet = "utf-8";
$mail->SMTPAuth = true;
$mail->Username = "###@gmail.com";
$mail->Password = "######";
$mail->SMTPSecure = "ssl";
$mail->Host = "smtp.gmail.com";
$mail->Port = "465";
$mail->setFrom('#####@gmail.com', 'example');
$mail->AddAddress($row[email]);
$mail->Subject = '54450065';
$mail->IsHTML(true);
$hl = <<<EOL
<h1>Welcome</h1>
<p>Your username is {$row[email]} .</p>
EOL;
$mail->Body = ($hl);
if($mail->Send())
{
echo "Message was Successfully Send :)";
}
else
{
echo "Mail Error - >".$mail->ErrorInfo;
}
}
?>
$mail = new PHPMailer();
inside the loop? – devproMail Error
? and check two more pointsAddAddress
and$mail->Body = ($hl);
– devpro$row['email']
– dev0