Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHPMailer错误-在cron作业中使用时消息正文为空_Php_Cron_Phpmailer - Fatal编程技术网

PHPMailer错误-在cron作业中使用时消息正文为空

PHPMailer错误-在cron作业中使用时消息正文为空,php,cron,phpmailer,Php,Cron,Phpmailer,我有一个脚本,检查连接的数据库上的匹配,当有一个匹配,电子邮件正在发送 我的Cronjob日志显示以下内容: Warning: file_get_contents(template/emailMatchLost.temp): failed to open stream: No such file or directory in /home/webbro/webapps/wrongle/script.php on line 54 Mailer Error: Message body empty

我有一个脚本,检查连接的数据库上的匹配,当有一个匹配,电子邮件正在发送

我的Cronjob日志显示以下内容:

Warning: file_get_contents(template/emailMatchLost.temp): failed to open stream: No such file or directory in /home/webbro/webapps/wrongle/script.php on line 54
Mailer Error: Message body empty

Warning: file_get_contents(template/emailMatchFound.temp): failed to open stream: No such file or directory in /home/webbro/webapps/wrongle/script.php on line 77
Mailer Error: Message body empty

Fatal error: Cannot redeclare phpmailerautoload() (previously declared in /home/webbro/webapps/wrongle/PHPMailer/PHPMailerAutoload.php:24) in /home/webbro/webapps/wrongle/PHPMailer/PHPMailerAutoload.php on line 31
<?php
include("settings/settings.inc.php");
$mysqli = new mysqli($config['server'], $config['username'], $config['password'], $config['database']);
/* check connection */
if ($mysqli->connect_errno) {
    error_Log("Connect failed: klote%s\n", $mysqli->connect_error, 0);
    exit();
}

$query = "SELECT * 
FROM LostFound AS Lost
INNER JOIN (
SELECT *
FROM LostFound
)Found ON Lost.Serial = Found.Serial
WHERE Lost.Type = 'Lost' and Found.Type = 'Found' And Lost.MatchId = 0 And Found.MatchId = 0";

if ($result = $mysqli->query($query)) 
{
    while ($row = $result->fetch_row()) 
    {
        $recIdLost = $row[0];
        $recIdFound = $row[9];
        $toLost = $row[2];
        $toFound = $row[11];
        $serial = $row[3];
        $place = $row[13];
        $reward = $row[14];

        $updateQuery[] = "UPDATE LostFound SET MatchId = '". $recIdFound. "', flag = '1' WHERE LostFound.RecId = '".$recIdLost."'";
        $updateQuery[] = "UPDATE LostFound SET MatchId = '". $recIdLost. "', flag = '1' WHERE LostFound.RecId = '".$recIdFound."'";

        $find = array("{Serial}", "{Place}", "{Reward}", "{EmailOwner}", "{EmailFinder}");
        $replace = array($serial, $place, $reward, $toLost, $toFound);

        require 'PHPMailer/PHPMailerAutoload.php';
        // Email to lost record
        $mailLost = new PHPMailer();
        $mailLost->isSMTP();
        $mailLost->SMTPDebug = $config['emailSMTPDebug'];
        $mailLost->Debugoutput = $config['emailSMTPDebugoutput'];
        $mailLost->Host = $config['emailSMTPHost'];
        $mailLost->Port = $config['emailSMTPPort'];
        $mailLost->SMTPSecure = $config['emailSMTPSecure'];
        $mailLost->SMTPAuth = $config['emailSMTPAuth'];
        $mailLost->Username = $config['emailSMTPUsername'];
        $mailLost->Password = $config['emailSMTPPassword'];
        $mailLost->setFrom($config['emailLost'], $config['emailNameLost']);
        $mailLost->addReplyTo($config['emailLost'], $config['emailNameLost']);
        $mailLost->addAddress($toLost, $toLost);
        $mailLost->Subject = $config['emailSubjectLostMatch'];
        $mailLost->msgHTML(str_replace($find, $replace, file_get_contents($config['emailBodyLostMatch'])), dirname(__FILE__));

        if (!$mailLost->send()) {
            error_log("Mailer Error: " . $mailLost->ErrorInfo, 0);
        } else {
            error_log("Message sent to " . $toLost, 0);
        }

        // Email to found record
        $mailFound = new PHPMailer();
        $mailFound->isSMTP();
        $mailFound->SMTPDebug = $config['emailSMTPDebug'];
        $mailFound->Debugoutput = $config['emailSMTPDebugoutput'];
        $mailFound->Host = $config['emailSMTPHost'];
        $mailFound->Port = $config['emailSMTPPort'];
        $mailFound->SMTPSecure = $config['emailSMTPSecure'];
        $mailFound->SMTPAuth = $config['emailSMTPAuth'];
        $mailFound->Username = $config['emailSMTPUsername'];
        $mailFound->Password = $config['emailSMTPPassword'];
        $mailFound->setFrom($config['emailFound'], $config['emailNameFound']);
        $mailFound->addReplyTo($config['emailFound'], $config['emailNameFound']);
        $mailFound->addAddress($toLost, $toLost);
        $mailFound->Subject = $config['emailSubjectFoundMatch'];
        $mailFound->msgHTML(str_replace($find, $replace, file_get_contents($config['emailBodyFoundMatch'])), dirname(__FILE__));

        if (!$mailFound->send()) {
            error_log("Mailer Error: " . $mailFound->ErrorInfo, 0);
        } else {
            error_log("Message sent to " . $toFound, 0);
        }
    }

    $result->close();

    if ($mysqli->multi_query(implode(';', $updateQuery)))
    {
        $i = 0; 
        do { 
            $i++; 
        } while ($mysqli->next_result()); 
    } 
    if ($mysqli->errno) { 
        error_log("Batch execution prematurely ended on statement".$i, 0);
        ob_start();                    // start buffer capture
        var_dump($object);             // dump the values
        $contents = ob_get_contents(); // put the buffer into a variable
        ob_end_clean();                // end capture
        error_log($contents); 
    } 
}

$mysqli->close();
error_log("Script done! ", 0);
?>
应运行的脚本如下所示:

Warning: file_get_contents(template/emailMatchLost.temp): failed to open stream: No such file or directory in /home/webbro/webapps/wrongle/script.php on line 54
Mailer Error: Message body empty

Warning: file_get_contents(template/emailMatchFound.temp): failed to open stream: No such file or directory in /home/webbro/webapps/wrongle/script.php on line 77
Mailer Error: Message body empty

Fatal error: Cannot redeclare phpmailerautoload() (previously declared in /home/webbro/webapps/wrongle/PHPMailer/PHPMailerAutoload.php:24) in /home/webbro/webapps/wrongle/PHPMailer/PHPMailerAutoload.php on line 31
<?php
include("settings/settings.inc.php");
$mysqli = new mysqli($config['server'], $config['username'], $config['password'], $config['database']);
/* check connection */
if ($mysqli->connect_errno) {
    error_Log("Connect failed: klote%s\n", $mysqli->connect_error, 0);
    exit();
}

$query = "SELECT * 
FROM LostFound AS Lost
INNER JOIN (
SELECT *
FROM LostFound
)Found ON Lost.Serial = Found.Serial
WHERE Lost.Type = 'Lost' and Found.Type = 'Found' And Lost.MatchId = 0 And Found.MatchId = 0";

if ($result = $mysqli->query($query)) 
{
    while ($row = $result->fetch_row()) 
    {
        $recIdLost = $row[0];
        $recIdFound = $row[9];
        $toLost = $row[2];
        $toFound = $row[11];
        $serial = $row[3];
        $place = $row[13];
        $reward = $row[14];

        $updateQuery[] = "UPDATE LostFound SET MatchId = '". $recIdFound. "', flag = '1' WHERE LostFound.RecId = '".$recIdLost."'";
        $updateQuery[] = "UPDATE LostFound SET MatchId = '". $recIdLost. "', flag = '1' WHERE LostFound.RecId = '".$recIdFound."'";

        $find = array("{Serial}", "{Place}", "{Reward}", "{EmailOwner}", "{EmailFinder}");
        $replace = array($serial, $place, $reward, $toLost, $toFound);

        require 'PHPMailer/PHPMailerAutoload.php';
        // Email to lost record
        $mailLost = new PHPMailer();
        $mailLost->isSMTP();
        $mailLost->SMTPDebug = $config['emailSMTPDebug'];
        $mailLost->Debugoutput = $config['emailSMTPDebugoutput'];
        $mailLost->Host = $config['emailSMTPHost'];
        $mailLost->Port = $config['emailSMTPPort'];
        $mailLost->SMTPSecure = $config['emailSMTPSecure'];
        $mailLost->SMTPAuth = $config['emailSMTPAuth'];
        $mailLost->Username = $config['emailSMTPUsername'];
        $mailLost->Password = $config['emailSMTPPassword'];
        $mailLost->setFrom($config['emailLost'], $config['emailNameLost']);
        $mailLost->addReplyTo($config['emailLost'], $config['emailNameLost']);
        $mailLost->addAddress($toLost, $toLost);
        $mailLost->Subject = $config['emailSubjectLostMatch'];
        $mailLost->msgHTML(str_replace($find, $replace, file_get_contents($config['emailBodyLostMatch'])), dirname(__FILE__));

        if (!$mailLost->send()) {
            error_log("Mailer Error: " . $mailLost->ErrorInfo, 0);
        } else {
            error_log("Message sent to " . $toLost, 0);
        }

        // Email to found record
        $mailFound = new PHPMailer();
        $mailFound->isSMTP();
        $mailFound->SMTPDebug = $config['emailSMTPDebug'];
        $mailFound->Debugoutput = $config['emailSMTPDebugoutput'];
        $mailFound->Host = $config['emailSMTPHost'];
        $mailFound->Port = $config['emailSMTPPort'];
        $mailFound->SMTPSecure = $config['emailSMTPSecure'];
        $mailFound->SMTPAuth = $config['emailSMTPAuth'];
        $mailFound->Username = $config['emailSMTPUsername'];
        $mailFound->Password = $config['emailSMTPPassword'];
        $mailFound->setFrom($config['emailFound'], $config['emailNameFound']);
        $mailFound->addReplyTo($config['emailFound'], $config['emailNameFound']);
        $mailFound->addAddress($toLost, $toLost);
        $mailFound->Subject = $config['emailSubjectFoundMatch'];
        $mailFound->msgHTML(str_replace($find, $replace, file_get_contents($config['emailBodyFoundMatch'])), dirname(__FILE__));

        if (!$mailFound->send()) {
            error_log("Mailer Error: " . $mailFound->ErrorInfo, 0);
        } else {
            error_log("Message sent to " . $toFound, 0);
        }
    }

    $result->close();

    if ($mysqli->multi_query(implode(';', $updateQuery)))
    {
        $i = 0; 
        do { 
            $i++; 
        } while ($mysqli->next_result()); 
    } 
    if ($mysqli->errno) { 
        error_log("Batch execution prematurely ended on statement".$i, 0);
        ob_start();                    // start buffer capture
        var_dump($object);             // dump the values
        $contents = ob_get_contents(); // put the buffer into a variable
        ob_end_clean();                // end capture
        error_log($contents); 
    } 
}

$mysqli->close();
error_log("Script done! ", 0);
?>


如果有人能给我指出正确的方向那就太好了。连接工作正常,所以这不会是问题所在。此外,我无法找到变量emailBodyLostMatch的来源。

错误消息非常清楚,但原因可能是从cron运行时,您的路径不同或未设置。在使用相对路径之前,请先使用绝对路径或cd到显式目录。

错误消息对我来说似乎很清楚。我投票决定将此问题作为非主题问题来结束,因为错误消息很清楚。