0

I've got a script running when a certain email address receives an email, procmail pipes to a PHP script, which is then parsed by Plancake, not many problems there. I've got an if statement on strpos, depending on if the body contains a certain text. For some reason, when I add the MySQL code, the entire thing stops working. Unfortunately the way it's setup I'm not quite sure how to add error checking. Here's the code:

<?php

require_once("PlancakeEmailParser.php");


 $rawEmail = '';
if (($fp = fopen('php://stdin', 'r')) !== false) {
    while (!feof($fp)) {
        $rawEmail .= fread($fp, 1024);
    }
    fclose($fp);

}

$emailParser = new PlancakeEmailParser($rawEmail);
$emailSubject = $emailParser->getSubject();
$emailBody = $emailParser->getPlainBody();
$emailHeader = $emailParser->getHeader('From');

$message = "FROM: ".$emailHeader."\n\nSubject: ".$emailSubject."\n\nBody: ".$emailBody;

$status = 4;

preg_match("/\d+/", "$emailSubject", $matches);
$number = $matches[0];

$short = substr($message, 0, strpos( $message, 'Begin'));
if (stripos($short,'approve') !== false) {
    echo 'true';
$msg = approve;
//file_put_contents('/home/symantec_mail/task' . $number . 'short.php',$msg);
file_put_contents('/home/symantec_mail/task' . $number . 'approve_short_reply.txt',$message);
file_put_contents('/home/symantec_mail/task' . $number . 'approve_reply.txt',$rawEmail);
}

if (stripos($short,'complete') !== false) {
    echo 'true';
$msg = complete;

when I uncomment the following mysqli code, everything stops.

//$mysqli = new mysqli("localhost", "user", "pass", "db");
//$update = $mysqli->prepare("UPDATE task_overview SET status = ? WHERE task_id = ?");
//$update->bind_param('ii', $status, $number");
//$update->execute();

rest of the code.

//file_put_contents('/home/symantec_mail/task' . $number . 'short.php',$msg);
file_put_contents('/home/symantec_mail/' . $number . 'complete_short_reply.txt',$message);
file_put_contents('/home/symantec_mail/' . $number . 'complete_reply.txt',$rawEmail);
}
?>

Really not sure why I can't execute these commands. I will point out that it's on a different shell account than my normal web server, although the PHP is still executing, I'm really not sure if I'm communicating with the MySQL server. Please if you have any suggestions, even if it's for error checking I'll greatly appreciate it.

dcclassics
  • 886
  • 1
  • 11
  • 34
  • Well you have no error checking now. After `new mysqli()`, test if it connected. `if (!$mysqli) echo mysqli_connect_error();` Likewise, you must test that the statement is prepared. `if (!$update) echo $mysqli->error;` – Michael Berkowski Feb 19 '13 at 23:53
  • I completely understand the premise, however I'm not sure where this is going to be echo'd. This is a script being run automatically by procmail, I have it outputting to files where possible, but not quite sure if I can do that for the error checking. – dcclassics Feb 19 '13 at 23:58
  • Anything logged by your script to standard error will end up in Procmail's log file. Also try running it from the command line with a canned message; see http://partmaps.org/era/mail/procmail-debug.html – tripleee Feb 20 '13 at 09:13

0 Answers0