使用>在cPanel上转发解析电子邮件

时间:2016-07-16 12:03:14

标签: php email parsing

我尝试使用cPanel在我的VPS上使用此E-mail parser

我已将传入的电子邮件转发到我的脚本,但我收到了一封错误的电子邮件:

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/../parser_3.php
   generated by domain.tld
   local delivery failed

The following text was generated during the delivery attempt:

------ pipe to |/home/../parser_3.php
      generated by test3@domain.tld ------

Could not exec '/home/../parser_3.php'
Reporting-MTA: dos; domain.tld

Action: failed
Final-Recipient: rfc822;|/home/../parser_3.php
Status: 5.0.0

由于我已经按原样使用了脚本,我想也许我需要安装一些php包才能让它工作?

chdir(dirname(__FILE__));
$fd = fopen("php://stdin", "r");
$email = "";
while (!feof($fd)) {
    $email .= fread($fd, 1024);
}
fclose($fd);

if(strlen($email)<1) {
    die(); 
}

// handle email
$lines = explode("\n", $email);

// empty vars
$from = "";
$to="";
$subject = "";
$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;
    }
}


$to = $unprocessed_email;

                $subject = 'TEST PARSER 3 - '.$date = date('md his', time()).'';

                $message = '<br><br> From: '. $from .' <br><br> To: '. $to .' <br><br> Subject: '. $subject .' <br><br> Headers: '. $headers .' <br><br> Message: '. $message .' <br><br><br>'.  print_r( $email, true ) .'';

                $headers = 'From: "Email-Parser" <parser@domain.tld>' . "\r\n" .

                           'MIME-Version: 1.0' . "\r\n" .
                           'Content-type: text/html; charset=UTF-8' . "\r\n".

                           'X-Mailer: PHPv: '.phpversion() . "\r\n" .


'';

                $result = mail($to, $subject, $message, $headers);


     if ($result) echo 'Mail accepted for delivery ';
     if (!$result) echo 'Test unsuccessful... '

或许它在PHP 7上根本不起作用?

结果将是解析传入的电子邮件。然后将它们发送到我的电子邮箱。稍后再添加到数据库,假设我得到解析工作。

0 个答案:

没有答案