我有一个数据库。字段是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('[email protected]'); // Add a recipient
$mail->addReplyTo($email);
$mail->addCC($emailcc);
做$mail->addCC($emailcc);
内循环:
while ($read = mysql_fetch_array($baca_kota)) {
$emailcc = $read['email'];
$mail->addCC($emailcc);
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句