尝试使用管道解析电子邮件时出错

时间:2014-11-26 05:55:25

标签: php

我正在尝试使用PIPING概念解析电子邮件。

文件权限设置为755

PHP版本:

PHP Version 5.5.17

PHP代码:

#!/usr/bin/php -q
    <?php
    // get mail via stdin
    $email = file_get_contents("php://stdin");
    // handle email
    $lines = explode("\n", $email);

    // set empty vars and explode message to variables
    $from = "";
    $subject = "";
    $to = "";
    $headers = "";
    $message = "";
    $splittingheaders = true;
        for ($i=0; $i < count($lines); $i++) {
        if ($splittingheaders) {
            // this is a header
            $headers .= $lines[$i]."\n";

            // look out for special headers
            if (preg_match("/^Subject: (.*)/", $lines[$i], $matches)) {
                $subject = $matches[1];
            }
            if (preg_match("/^From: (.*)/", $lines[$i], $matches)) {
                $from = $matches[1];
            }
            if (preg_match("/^To: (.*)/", $lines[$i], $matches)) {
                $to = $matches[1];
            }
        } else {
            // not a header, but message
            $message .= $lines[$i]."\n";
        }

        if (trim($lines[$i])=="") {
            // empty line, header section has ended
            $splittingheaders = false;
        }
    }

    // connect to mysql and insert data
    $con = mysql_connect('localhost','myusername','myusername');
    mysql_select_db('mydatabase', $con);

    $sql = "INSERT INTO email(emailfrom, emailsubject) VALUES ('$from', '$subject')";
    $res = mysql_query($sql,$con);
    if (!$res) {
        print("SQL statement failed with error:\n");
        print(" ".mysql_get_last_message()."\n");
    } else {
        print("One data row inserted.\n");
    }
    mysql_close($con);
    ?>

错误:

This message was created automatically by mail delivery software.

    A message that you sent could not be delivered to one or more of its
    recipients. This is a permanent error. The following address(es) failed:

      pipe to |/home/puzzledboy/public_html/emailparse/mailparse.php
        generated by support@puzzledboy.com
        local delivery failed

    The following text was generated during the delivery attempt:

    ------ pipe to |/home/puzzledboy/public_html/emailparse/mailparse.php
           generated by support@puzzledboy.com ------

    Could not exec '/home/puzzledboy/public_html/emailparse/mailparse.php'

    ------ This is a copy of the message, including all the headers. ------

0 个答案:

没有答案