Email piping to script problem
mahe4us
Junior Poster in Training
55 posts since Sep 2006
Reputation Points: 10
Solved Threads: 0
Hi mahe4us,
When you pipe to the php script, you must make sure that the php script does not send any output.
It looks like your php script is has the output:
PHP Warning: Zend Optimizer does not support this version of PHP - please upgrade to the latest version of Zend Optimizer in Unknown on line 0
Even output from an error like above will cause the Mail Delivery Software - Mail Transport Agent (MTA) - to assume that the returned output from the script is an error message, which it will report back to the sender of the email.
What you can do is try to suppress errors in your php using the ini_set() function or error_reporting() funciton.
You can also use output buffering. set ob_start() at the beginning of your script, then ob_get_contents() at the end of your script to retrieve all output (including errors). Then you can send this output somewhere else, like to an email for debugging, or write it to a text file. Then you can remove all the output the script produced using ob_clean();
eg:
[PHP]<?php
// start output buffering
ob_start();
// get your email from stdin
$email = file_get_contents('php://stdin');
// do stuff
// log your email to logfile
$fp = fopen('log.txt', 'r');
if ($fp) {
fwrite($fp, $email, strlen($email));
fclose();
}
// or send you a copy
mail('myemail@mydomain.com', 'email received', $email, 'from: phpscript@mydomain.com');
// clean the output
ob_end_flush();
?>[/PHP]
Another way to suppress headers is using the -q option or redirect the output to /dev/null which will suppress the output:
| php -q /home/xxxx/public_html/xxxx/mail.php
or
| php -q /home/xxxx/public_html/xxxx/mail.php >> /dev/null
digital-ether
Nearly a Posting Virtuoso
1,293 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101
HI digital-ether,
First I would give my thanks to you for your nice reply once again to me. I applied the error suppress methods in php script. But still the mail delivery failed message come with me. But the script works.
Also I used the -q in script path in cpanel
| php -q /home/xxxx/public_html/xxxx/mail.php >> /dev/null
This method also not stop the mail delivery message.
Iam using #!/usr/bin/php -q at start of the php script. Please suggest your ideas if any error i have made.
Thanks
mahe4us
Junior Poster in Training
55 posts since Sep 2006
Reputation Points: 10
Solved Threads: 0
Only advice I can give is to try differnt setups.
Try a setup like:
| php -q /home/xxxx/public_html/xxxx/mail.php
remove the: #!/usr/bin/php -q
And use phps ouput buffering. Start with ob_start() and end your script with ob_end_clean();
Is your php running as a CGI or Apache module?
digital-ether
Nearly a Posting Virtuoso
1,293 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101
Hi Digita-ether,
I removed the #!/usr/bin/php -q in scrip. Also I uses the ob_start() and ob_end_clean(). For your reference I Paste my script below.
-----------------------------------
<?php
// start output buffering
ob_start();
// read from stdin
$fd = fopen("php://stdin", "r");
$email = "";
while (!feof($fd)) {
$email .= fread($fd, 1024);
}
fclose($fd);
// handle email
$lines = explode("\n", $email);
// empty vars
$from = "";
$subject = "";
$headers = "";
$message = "";
$splittingheaders = true;
for ($i=0; $i
----------------------
I think my server is running php through apache module. But iam not sure because i dont know how to find it.
Thanks..
mahe4us
Junior Poster in Training
55 posts since Sep 2006
Reputation Points: 10
Solved Threads: 0
Take a look at your phpinfo().
(create a file with <?php phpinfo(); ?> and view it online).
Then look for "Server API" right at the top. It should be "CGI" or "Apache" etc.
digital-ether
Nearly a Posting Virtuoso
1,293 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101
Hi Digital-ether,
I have seen Server API by using phpinfo() in my server. I looked the page online and it denoted as "apache".
Thanku..
mahe4us
Junior Poster in Training
55 posts since Sep 2006
Reputation Points: 10
Solved Threads: 0
Hi Digital-ether,
I have seen Server API by using phpinfo() in my server. I looked the page online and it denoted as "apache".
Thanku..
Looks like you're running php as an apache module.
Is your php script actualy being run? If it is you should get the email from:
[PHP]mail('mydomain@mydomain.com', 'email received', $email, 'from: Server');[/PHP]
Also, has the mailer-daemon notification email changed since you removed the shebang line or added the php buffering functions?
could you post the email from the mailer-daemon (failure notification) if its changed..
digital-ether
Nearly a Posting Virtuoso
1,293 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101
Hi Digital-ether,
I have tried all the options. I have used the script with and without shebang code and buffering actions. All the way the mailer daemon notification arrived. Iam sure that the script works fine. But the bounce mail also comes to me with an error indicating.
PHP Warning: Zend Optimizer does not support this version of PHP - please upgrade to the latest version of Zend Optimizer in Unknown on line 0
Iam also tried very much but still Iam not get any solution for this...
Thanku
mahe4us
Junior Poster in Training
55 posts since Sep 2006
Reputation Points: 10
Solved Threads: 0
Hi Digital-ether,
I have tried all the options. I have used the script with and without shebang code and buffering actions. All the way the mailer daemon notification arrived. Iam sure that the script works fine. But the bounce mail also comes to me with an error indicating.
PHP Warning: Zend Optimizer does not support this version of PHP - please upgrade to the latest version of Zend Optimizer in Unknown on line 0
Iam also tried very much but still Iam not get any solution for this...
Thanku
Looks like your only fix for this is to upgrade the Zend Optimizer to support the php version you're using.
This error is being generated on line 0, which means that the output is sent before buffering starts with ob_start();
I did some tests and it doesn't seem to matter what you put in the email pipe in Cpanel.
If you place the -q option or even redirect output to /dev/null, it still will send a mailer-daemon notification back to the sender if the script creates output. This may be server dependant, MTA dependant? I dont know..
If you're on a rented server you'll have to ask your hosting to upgrade Zend Optimizer.
If you can't upgrade Zend Optimizer for some reason, you can turn off error reporting in php.ini.
Using the function error_reporting(0); (at runtime) in side your php code won't work (just like ob_start()) because the error is generated before your php is even run.
Otherwise you may have to pipe the email to a perl script or something else that doesn't create ouput.
digital-ether
Nearly a Posting Virtuoso
1,293 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101
Hi,
this is a test =
mail.
mahe4us
Junior Poster in Training
55 posts since Sep 2006
Reputation Points: 10
Solved Threads: 0