I know it may sound like duplicate but my problems a bit different so i'm fetching email from my database use loop to get the data the problem was even if passing 1 email at the addaddress() function at a time all the recipient receive the same email multiple times based on the number of recipient example if my recipient is three each recipient will receive three email each this is my code:
for ($i = 0; $i <= (6) - 1; $i++) {
$q = Yii::app()->db->createcommand("select user_other_email from user_account LIMIT 6")->queryall();
$ty = '';
for ($b = 0; $b < count($q); $b++) {
$ty = $email = $q[$b]['user_other_email'];
$msg = "Test this!";
$adminemail = "email@gmail.com";
$name=' = ?UTF-8?B?' . base64_encode($adminemail) . '?=';
$subject = 'TEST';
$headers = "From: $name <{".$adminemail."}>
" .
"Reply-To: {$adminemail}
".
"MIME-Version: 1.0
".
'Content-type: text/html; charset=iso-8859-1' . "
";
$this->mailsend2($ty,$adminemail,$subject,$msg);
}
}
AND this is my mailer function:
public function mailsend2($to, $from, $subject, $message) {
$mail = Yii::app()->Smtpmail;
$mail->SetFrom($from, 'Test');
$mail->Subject = $subject;
$mail->MsgHTML($message);
$mail->AddAddress($to);
if (!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
}
really dont know what is wrong with this