Reputation: 3654
It took me a few hours but I finally figured out how to pipe mail to my PHP script with cPanel X3.
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: [email protected]";
$to = "[email protected]";
$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 [email protected]
The following text was generated during the delivery attempt:
------ pipe to |/home/PATH/TO/SCRIPT/parse.ph
generated by [email protected] ------
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: <[email protected]>
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 <[email protected]>)
id 1QpAdr-0008UY-MO
for [email protected]; Thu, 04 Aug 2011 22:00:07 -0500
Received: by fxe6 with SMTP id 6so2641925fxe.3
for <[email protected]>; 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: [email protected]
Date: Thu, 4 Aug 2011 22:59:44 -0400
Message-ID: <CAHxz2PpNoNWRakeP2JoN8cdmPfz=HrYd5N2vZ4aqb9E_vLiUjw@mail.gmail.com>
Subject: Hahahahha
To: [email protected]
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:
|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. The following were duplicated:
extension=pdo.so
extension=pdo_sqlite.so
extension=sqlite.so
extension=pdo_mysql.so
Upvotes: 0
Views: 5579
Reputation: 48387
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. These may be generating back scatter depending on the MDA. There's also the undeliverable message - which is an issue with your Exim config.
Your receiving script will also exit and close the STDIN pipe before reading from it. Really you should read up to the EOF and exit with an explicit return code (0 for success)
Upvotes: 0
Reputation: 12537
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.
You could try to suppress those warnings by setting 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.
Upvotes: 2
Reputation: 89
The only issue I see is the $headers = "From: [email protected]";
should be $headers = "From: [email protected]\r\n";
Upvotes: 0