【发布时间】:2017-06-07 17:42:10
【问题描述】:
我有一个数据库。这些字段是id、email 和city。我想向我数据库中的所有电子邮件发送一些电子邮件。
例如:我住在一个城市,所以我想向所有与我所在城市匹配的电子邮件发送电子邮件。
我的方法代码是这样写的:
$kota = mysql_real_escape_string(stripcslashes( $_POST['kota']));
$baca_kota = mysql_query("SELECT email FROM conselor WHERE kota='$kota'");
while($read = mysql_fetch_array($baca_kota))
{
$emailcc = $read['email'];
}
require '../phpmailer/PHPMailerAutoload.php';
require '../phpmailer/class.phpmailer.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'xxxxxxxxxxxxxxxxxx'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'xxxxxxxxxxxxxxx'; // SMTP username
$mail->Password = 'xxxxxxxxxxxxxxx'; // SMTP password
$mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465; // TCP port to connect to
$mail->setFrom($email,$name);
$mail->addAddress('stevanlai04@gmail.com'); // Add a recipient
$mail->addReplyTo($email);
$mail->addCC($emailcc);
【问题讨论】: