【发布时间】:2017-02-12 09:42:54
【问题描述】:
我正在使用 PHPMailer。
我在email 列的users 表中记录用户电子邮件。我的表中还有category 列。我想向这些用户发送电子邮件。例如,我想向category 列中具有tech 值的用户发送电子邮件。我可以这样做,但是当我发送时,PHPMailer 发送我的电子邮件,就像
first user -> first column email
second user -> first column email
second column email
third user -> first column email
second column email
third column email
我只想先发送user -> first column email,second user -> second column email。
我现在有这些代码。
<?php
require_once("class.phpmailer.php");
if($_POST['message']){
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->IsHTML(true);
$mail->Host = "host.name.net";
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->CharSet ="utf-8";
$mail->Username = "mail@mymail.com";
$mail->Password = "pass";
$mail->SetFrom("hi@mymail.com", "my mail name");
$categorychoose = $_POST['categorychoose'];
$query = (" SELECT email FROM users WHERE category LIKE '$categorychoose' ");
$result = mysql_query($query);
while( $data = mysql_fetch_assoc($result) )
{
$mail->AddAddress($data["email"]);
$mail->Subject = $_POST['subject'];
$mail->Body = $_POST['message'];
if(!$mail->Send())
{
echo "<h4>not send</h4>";
} else {
echo "<h4>send</h4>";
}
}
}
?>
【问题讨论】:
-
这不可能是你的全部代码吗?
-
我也有表单代码和一些phpmailer设置代码,但我没有问题。
-
每次在新代码中使用the
mysql_数据库扩展a Kitten is strangled somewhere in the world 时,它都已被弃用,并且已经存在多年,并且在 PHP7 中永远消失了。如果您只是学习 PHP,请花精力学习PDO或mysqli数据库扩展。 Start here -
@RiggsFolly Little Bobby Tables 很好,AFAIK - 只是他学校的数据库被盗了。