PHP Mail Function waits and not working with foreach loop

五迷三道 提交于 2020-01-25 14:59:43

问题


I am trying to send mail to all users that have no created reports in one month, also trying to send mail to this users with foreach loop and with mail function, when i refresh one by one then it sends mail one by one, then it works. i want to send mail to all this users in one time.

        $from = "xxx@xxx.com";
        $subject = "";
        $headers = "";
        $inc = 0;
        foreach($query->result_array() as $row)
        {
            $inc++;
            $to = $row['us_email'];
            $to_date = $row['report_date'];
            if($to_date != "0000-00-00")
            {
                $subject = "Hello! (Reports Are Not Created).";

                //begin of HTML message 
                $message = "1 month above you should create reports.";
            }
            else if($to_date == "0000-00-00")
            {
                $subject = "Hello! (Generate Reports).";

                //begin of HTML message 
                $message ="generate reports to get more.";
            }
            $headers  = "MIME-Version: 1.0" . "\r\n";
            $headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
            $headers .= "To: User <".$to.">, Admin <".$from.">" . "\r\n";
            $headers .= "From: Complete Online Marketing <".$from.">" . "\r\n";
            $headers .= "Reply-To: Recipient Name <".$from.">";
            $headers .= "Cc: [email]".$from."[/email]" . "\r\n";
            $headers .= "Bcc: [email]".$from."[/email]" . "\r\n";


            // now lets send the email.
            if(mail($to, $subject, $message, $headers))
            {
                echo $inc.") ".$row['us_firstname']." ".$row['us_lastname']." - Sending Success...\n";
                $ins = array('report_mail'=>'0');
                $this->db->update('se_user', $ins, array('us_id' => $row['us_id']));
            }
            else
            {
                echo $inc.") ".$row['us_firstname']." ".$row['us_lastname']." - Sending Fail...\n";
            }
        }

来源:https://stackoverflow.com/questions/25870594/php-mail-function-waits-and-not-working-with-foreach-loop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!