当我点击sendForm按钮时,我想为我的所有活动用户发送一封电子邮件。
我下面有这个代码,我有一个While循环,可以为我的每封电子邮件发送一封电子邮件(状态=活动)。
但这封电子邮件只是为我在表格中的第一封电子邮件发送的,而不是为我收到的每封邮件发送的。
有人知道为什么会发生这种事吗?
if(isset($_POST['sendForm']))
{
$verifyUser= $pdo->prepare("SELECT * FROM users WHERE status = ?");
$verifyUser->bindValue(1, 'active');
$verifyUser->execute();
$verifyUserRows= $verifyUser->rowCount();
if($verifyUserRows<= '0')
{
echo 'there are no active warnings';
}
else
{
while ($verifyUserResult= $verifyUser->fetch(PDO::FETCH_ASSOC))
{
$date = date('d/m/Y H:i');
$msg = "
Hi, this is my message!
Send at $data
";
sendMail('My subject',$msg,MAILUSER,$verifyUserResult['email']);
echo 'Email sent with sucess';
return;
}
}
问题是您的退货;语句在while循环中。
这个特定循环中的return语句将导致循环终止。在这种情况下,您已经将其作为循环的最后一条语句,因此它将处理您要发送的第一封电子邮件,然后终止。
要解决此问题,请删除退货;声明。