I'm using PHPMailer.
I record user e-mails at users
table in email
column. Also I have category
column in my table. I want to send e-mail to these users. For example, I want to send e-mail to users who has tech
value in category
column. I can do this but when I send, PHPMailer
send my e-mail like
first user -> first column email
second user -> first column email
second column email
third user -> first column email
second column email
third column email
I just want to send first user -> first column email
, second user -> second column email
.
I have these codes right now.
<?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>";
}
}
}
?>