Php 我的第一个CRON作业出错。。。[包括错误消息]

Php 我的第一个CRON作业出错。。。[包括错误消息],php,cron,mysqli,cpanel,hostmonster,Php,Cron,Mysqli,Cpanel,Hostmonster,我在运行cron作业时遇到了一个小问题。我创建此脚本是为了帮助我在数据库中的日期与今天的日期匹配时自动发送电子邮件公告,否则它将向管理员发送电子邮件,通知他们没有发送公告。我检查了所有的电子邮件,以及电子邮件组收件箱,没有收到任何电子邮件。下面编写的脚本,后跟cron作业运行时收到的电子邮件错误。提前谢谢! //Set variable which contains the query to the database $userbcc = $connection->prepare("SEL

我在运行cron作业时遇到了一个小问题。我创建此脚本是为了帮助我在数据库中的日期与今天的日期匹配时自动发送电子邮件公告,否则它将向管理员发送电子邮件,通知他们没有发送公告。我检查了所有的电子邮件,以及电子邮件组收件箱,没有收到任何电子邮件。下面编写的脚本,后跟cron作业运行时收到的电子邮件错误。提前谢谢!
//Set variable which contains the query to the database
$userbcc = $connection->prepare("SELECT email FROM users ORDER BY email ASC") or die("could not connect");

//Execute the query through MySQLi
$userbcc->execute();

//Stores the number for counting
$userbcc->store_result();

//Bind results to their variables
$userbcc->bind_result($email);

//While results 
while ($userbcc->fetch()) {
    $userlist .= $email . ",";
}

//Count the rows
$user_rows = $userbcc->num_rows;

$userbcc->close();


//Set and sanitize the variable which contains perameter
$today = date("Y-m-d 00:00:00");

//Set variable which contains the query to the database
$mailpromo = $connection->prepare("SELECT id,venid,title,intro,body,sdate,edate FROM venpromo WHERE `sdate` =  ?") or die("could not connect");

//Set the query 'WHERE state = ?' to the query
$mailpromo->bind_param("s",$today);

//Execute the query through MySQLi
$mailpromo->execute();

$mailpromo->store_result();

//Bind results to their variables
$mailpromo->bind_result($id,$venid,$title,$intro,$body,$sdate,$edate);

$ad_rows = $mailpromo->num_rows;

//While results 
while ($mailpromo->fetch()) {
    $to = "[EMAIL ADDRESS]";
    $from = "[EMAIL ADDRESS]";
    $subject = "A New Promo Starts Today! \"$title\"";
    $message = "MESSAGE";
        $headers = "From: Norris Portal Intranet System <[EMAIL ADDRESS]>\r\n";
    $headers .= "Reply-To: ". strip_tags($from) . "\r\n";
    $headers .= "BCC: " . substr($userlist, 0, -1) . "\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
    if ($from != "" && $to != "" && $subject != "" && $message != "") {
        if (mail($to, $subject, $message, $headers)) {
            $mailsuccess = 1;
        } else {
            $mailfail = "1";
        }
    } else {
        $mailfail = "1";
    }
}

$mailpromo->close();


if ($ad_rows == 0) {
    $to = "[EMAIL ADDRESS]";
    $from = "[EMAIL ADDRESS]";
    $subject = "There were no promo's pulled from today's bulletin.";
    $message = "There were no promo's emailed to the staff today. Only promo's with a start day of today will be emailed to the staff.";
    $headers = "From: Norris Portal Intranet System <[EMAIL ADDRESS]>\r\n";
    $headers .= "Reply-To: ". strip_tags($from) . "\r\n";
    $headers .= "BCC: [EMAIL ADDRESS]\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
    if ($from != "" && $to != "" && $subject != "" && $message != "") { 
        if (mail($to, $subject, $message, $headers)) { 
            $mailsuccess = 1;
        } else {
            $mailfail = "1";
        }
    } else {
        $mailfail = "1";
    }
}

?>

我重写了我的代码,这是有效的。。。解决方案是先提取内容,然后使用while循环逐个发送内容,而不是将所有电子邮件添加到BCC:list中。。。
//Set variable which contains the query to the database
$mailpromo = $connection->prepare("SELECT id,venid,title,intro,body,sdate,edate FROM venpromo WHERE `sdate` =  ?") or die("could not connect");

//Set the query 'WHERE state = ?' to the query
$mailpromo->bind_param("s",$today);

//Execute the query through MySQLi
$mailpromo->execute();

//Stores the number for counting
$mailpromo->store_result();

//Bind results to their variables
$mailpromo->bind_result($id,$venid,$title,$intro,$body,$sdate,$edate);

//Bind results to their variables
$mailpromo->fetch();

//Count the number of bulletins today
$mail_count = $mailpromo->num_rows;

//Close the session
$mailpromo->close();



//Set variable which contains the query to the database
$userbcc = $connection->prepare("SELECT email FROM users") or die("could not connect");

//Execute the query through MySQLi
$userbcc->execute();

//Stores the number for counting
$userbcc->store_result();

//Bind results to their variables
$userbcc->bind_result($email);

//While results 
while ($userbcc->fetch()) {


    $to = $email;
    $from = "[email held]";
    $subject = "A New Promo Starts Today! \"$title\"";
    $message = "[content held]"

    $headers = "From: [email held] \r\n";
    $headers .= "Reply-To: ". strip_tags($from) . "\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
    if ($from != "" && $to != "" && $subject != "" && $message != "") {
        if (mail($to, $subject, $message, $headers)) {
            $mailsuccess = 1;
        } else {
            $mailfail = "1";
        }
    } else {
        $mailfail = "1";
    }




}

//Close the session
$userbcc->close();


if ($mail_count == 0) {
    $to = "[email held]";
    $from = "[email held]";
    $subject = "There were no promo's pulled from today's bulletin.";
    $message = "There were no promo's emailed to the staff today. Only promo's with a start day of today will be emailed to the staff.";
    $headers = "[email held]\r\n";
    $headers .= "Reply-To: ". strip_tags($from) . "\r\n";
    $headers .= "BCC: [email held]\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
    if ($from != "" && $to != "" && $subject != "" && $message != "") { 
        if (mail($to, $subject, $message, $headers)) { 
            $mailsuccess = 1;
        } else {
            $mailfail = "1";
        }
    } else {
        $mailfail = "1";
    }
}

?>

$userlist
?@KarolyHorvath-substr($userlist,0,-1)中的额外逗号已经从电子邮件列表中删除了最后一个逗号。谢谢你!(对不起,我不知道如何突出显示此代码。)
//Set variable which contains the query to the database
$mailpromo = $connection->prepare("SELECT id,venid,title,intro,body,sdate,edate FROM venpromo WHERE `sdate` =  ?") or die("could not connect");

//Set the query 'WHERE state = ?' to the query
$mailpromo->bind_param("s",$today);

//Execute the query through MySQLi
$mailpromo->execute();

//Stores the number for counting
$mailpromo->store_result();

//Bind results to their variables
$mailpromo->bind_result($id,$venid,$title,$intro,$body,$sdate,$edate);

//Bind results to their variables
$mailpromo->fetch();

//Count the number of bulletins today
$mail_count = $mailpromo->num_rows;

//Close the session
$mailpromo->close();



//Set variable which contains the query to the database
$userbcc = $connection->prepare("SELECT email FROM users") or die("could not connect");

//Execute the query through MySQLi
$userbcc->execute();

//Stores the number for counting
$userbcc->store_result();

//Bind results to their variables
$userbcc->bind_result($email);

//While results 
while ($userbcc->fetch()) {


    $to = $email;
    $from = "[email held]";
    $subject = "A New Promo Starts Today! \"$title\"";
    $message = "[content held]"

    $headers = "From: [email held] \r\n";
    $headers .= "Reply-To: ". strip_tags($from) . "\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
    if ($from != "" && $to != "" && $subject != "" && $message != "") {
        if (mail($to, $subject, $message, $headers)) {
            $mailsuccess = 1;
        } else {
            $mailfail = "1";
        }
    } else {
        $mailfail = "1";
    }




}

//Close the session
$userbcc->close();


if ($mail_count == 0) {
    $to = "[email held]";
    $from = "[email held]";
    $subject = "There were no promo's pulled from today's bulletin.";
    $message = "There were no promo's emailed to the staff today. Only promo's with a start day of today will be emailed to the staff.";
    $headers = "[email held]\r\n";
    $headers .= "Reply-To: ". strip_tags($from) . "\r\n";
    $headers .= "BCC: [email held]\r\n";
    $headers .= "MIME-Version: 1.0\r\n";
    $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
    if ($from != "" && $to != "" && $subject != "" && $message != "") { 
        if (mail($to, $subject, $message, $headers)) { 
            $mailsuccess = 1;
        } else {
            $mailfail = "1";
        }
    } else {
        $mailfail = "1";
    }
}

?>