简体   繁体   English

cPanel管道邮件到PHP脚本

[英]cPanel pipe mail to PHP script

It took me a few hours but I finally figured out how to pipe mail to my PHP script with cPanel X3. 我花了几个小时,但我终于想出了如何使用cPanel X3将邮件传递给我的PHP脚本。

The actual parsing script is just a test script that I setup which emails me when it's executed. 实际的解析脚本只是我设置的测试脚本,它在执行时通过电子邮件发送给我。

#!/usr/local/bin/php -q
<?php
$headers = "From: test@email.com";
$to = "myemail@gmail.com";
$subject = "Recieved";
$body = "Message recieved.";
$mail = mail($to, $subject, $body, $headers);

The above script executes correctly and receives data, even though it's receiving the mail it's also sending back the following: 上面的脚本正确执行并接收数据,即使它正在接收邮件,它也会发回以下内容:

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/PATH/TO/SCRIPT/parse.php
   generated by test@email.com

The following text was generated during the delivery attempt:

------ pipe to |/home/PATH/TO/SCRIPT/parse.ph
  generated by test@email.com ------

PHP Warning:  Module 'PDO' already loaded in Unknown on line 0
PHP Warning:  Module 'pdo_sqlite' already loaded in Unknown on line 0
PHP Warning:  Module 'SQLite' already loaded in Unknown on line 0
PHP Warning:  Module 'pdo_mysql' already loaded in Unknown on line 0

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

Return-path: <myemail@gmail.com>
Received: from mail-fx0-f44.google.com ([209.85.161.44])
       by my.server.com with esmtps (TLSv1:RC4-SHA:128)
       (Exim 4.69)
       (envelope-from <myemail@gmail.com>)
       id 1QpAdr-0008UY-MO
       for test@email.com; Thu, 04 Aug 2011 22:00:07 -0500
Received: by fxe6 with SMTP id 6so2641925fxe.3
       for <test@email.com>; Thu, 04 Aug 2011 20:00:04 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
       d=gmail.com; s=gamma;
       h=mime-version:from:date:message-id:subject:to:content-type;
       bh=gqxzpu6OEZTUs6uTT1G+NLaRvZh0HIOfcrOh1KtUuqw=;
       b=ICOQ1YpNQZKXxAB5DCguFui6aCSqg9wMDaj8S+1iuNkJQhGL8otqT8zRdRU8i+dngU
        +KjDbSPNLdt52PGLqbz4v48MKWUCeaTo/xwa4Pftix6d63x6yqwU4/Hy9ZG9dhNiVHYM
        goSQb+InqzTgw3msyWMsw75Mddwh/HK4I8fv0=
Received: by 10.204.151.216 with SMTP id d24mr532167bkw.304.1312513204131;
 Thu, 04 Aug 2011 20:00:04 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.204.23.196 with HTTP; Thu, 4 Aug 2011 19:59:44 -0700 (PDT)
From: myemail@gmail.com
Date: Thu, 4 Aug 2011 22:59:44 -0400
Message-ID: <CAHxz2PpNoNWRakeP2JoN8cdmPfz=HrYd5N2vZ4aqb9E_vLiUjw@mail.gmail.com>
Subject: Hahahahha
To: test@email.com
Content-Type: multipart/alternative; boundary=0015175dd9cc4b987d04a9b94b71

--0015175dd9cc4b987d04a9b94b71
Content-Type: text/plain; charset=ISO-8859-1

awda asd asdqwd a xzccz

--0015175dd9cc4b987d04a9b94b71
Content-Type: text/html; charset=ISO-8859-1

awda asd asdqwd a xzccz

--0015175dd9cc4b987d04a9b94b71--    

This is the path I used in cPanel: 这是我在cPanel中使用的路径:

|php -q -n /PATH/TO/SCRIPT/parse.php

Why am I still getting that error from my server if the script is being executed? 如果脚本正在执行,为什么我仍然从我的服务器收到错误?

EDIT: I figured out what the issue was. 编辑:我弄清楚问题是什么。 My php.ini file wasn't setup properly. 我的php.ini文件设置不正确。 The following were duplicated: 以下是重复的:

extension=pdo.so
extension=pdo_sqlite.so
extension=sqlite.so
extension=pdo_mysql.so

The reason for the "error mail" is that the MTA thinks there was an error if the executed program has written something on stdout or stderr (I'm not shure) - this is what php does when it is emitting a warning. “错误邮件”的原因是MTA认为如果执行的程序在stdoutstderr上写了一些东西是stderr (我不是shure) - 这就是php在发出警告时所做的事情。

You could try to suppress those warnings by setting error_reporting: 您可以尝试通过设置error_reporting来抑制这些警告:

|php -n -d error_reporting=E_ERROR /PATH/TO/SCRIPT/parse.php

If that doesn't work then try to eliminate all output: 如果这不起作用,那么尝试消除所有输出:

|php -d display_errors=off -d display_startup_errors=off -d error_log=/dev/null -n /PATH/TO/SCRIPT/parse.php

But that way you won't see any errors like syntax errors which may be not desired. 但是这样你就不会看到任何可能不需要的语法错误等错误。

The only issue I see is the $headers = "From: test@email.com"; 我看到的唯一问题是$headers = "From: test@email.com"; should be $headers = "From: test@email.com\\r\\n"; 应该是$headers = "From: test@email.com\\r\\n";

The above script executes correctly and receives data, even though it's receiving the mail 上面的脚本正确执行并接收数据,即使它正在接收邮件

? The script you've shown does not receive emails it only sends them. 您显示的脚本不会收到仅发送的电子邮件。

Why am I still getting that error 为什么我仍然会收到这个错误

Which error? 哪个错误? There are PHP errors due to a misconfig - but these are not preventing the script from running. 由于错误配置导致PHP错误 - 但这些并不妨碍脚本运行。 These may be generating back scatter depending on the MDA. 这些可能会产生反向散射,具体取决于MDA。 There's also the undeliverable message - which is an issue with your Exim config. 还有无法传递的消息 - 这是您的Exim配置的问题。

Your receiving script will also exit and close the STDIN pipe before reading from it. 您的接收脚本也会在读取之前退出并关闭STDIN管道。 Really you should read up to the EOF and exit with an explicit return code (0 for success) 真的,您应该阅读EOF并使用显式返回码退出(0表示成功)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM