I have a script which checkes the connected database on matches, when a match is there, emails are being send.
My Cronjob logs say the following:
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
The script that should be running is the following:
<?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
", $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);
?>
If anyone could point me in the right directions that would be great. The connections works so that can't be the problem. Also I can not find where the variable emailBodyLostMatch is coming from.
The error messages are pretty clear, but the cause is probably that your PATH is different or unset when run from cron. Use absolute paths, or cd to an explicit directory before using relative paths.