gpt4 book ai didi

php - 如何在 foreach 循环中回显消息一次

转载 作者:行者123 更新时间:2023-12-01 04:36:43 24 4
gpt4 key购买 nike

假设我有一个这样的查询:

    foreach ($emailist AS $addy) {
if(@mail($to, $subject, $message, $headers))
{
echo "Mail Sent";
}
else
{
echo "e";
}
}

我有一个调用响应的 jquery

success :  function(data)
{
if(data=="Mail Sent")
{
$("#error").fadeIn(1000, function(){
$("#error").html('<div class="alert alert-success"> <span class="glyphicon glyphicon-info-sign"></span> &nbsp; Successfully Sent!!</div>');
$("#btn-submit").html('<span class="fa fa-check"></span> &nbsp; Sent');

});
}
else if(data=="e")
{
$("#error").fadeIn(1000, function(){
$("#error").html('<div class="alert alert-success"> <span class="glyphicon glyphicon-info-sign"></span> &nbsp; Saved only to database and mail not sent!!</div>');
$("#btn-submit").html('<span class="fa fa-check"></span> &nbsp; Sent');

});
} }

如何让邮件发送在这样的循环中回显一次?

我已经尝试了一切,但没有成功。每次我运行程序时,邮件已发送都会在ajax响应中显示程序循环的次数,而不是成功发送!!

最佳答案

看起来您可能正在尝试查看所有电子邮件是否已成功发送?

$errorsExist = false;

foreach ($emailist AS $addy) {
//errors exist if the email fails now, or did in the past
$errorsExist = !@mail($to, $subject, $message, $headers) || $errorsExist;
}

if ($errorsExist) {
echo "e";
} else {
echo "Mail Sent";
}

关于php - 如何在 foreach 循环中回显消息一次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50861464/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com