我使用下面的代码向mysql数据库uing phpmailer中的所有用户发送电子邮件。我的问题是..邮件没有发送给所有收件人,但邮件发送给一个或两个收件人。代码中是否有任何问题。谢谢
<?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;
}
}
?>
答案 0 :(得分:0)
您需要为要发送到的每个电子邮件地址调用一次AddAddress函数。此函数只有两个参数:recipient_email_address和recipient_name。收件人姓名是可选的,如果不存在则不会被使用。
A
您可以使用数组存储收件人,然后使用for循环。我希望它有所帮助。