Email piping to script problem

Reply

Join Date: Sep 2006
Posts: 54
Reputation: mahe4us is an unknown quantity at this point 
Solved Threads: 0
mahe4us's Avatar
mahe4us mahe4us is offline Offline
Junior Poster in Training

Email piping to script problem

 
0
  #1
Sep 20th, 2006
Hi everyone,

I have set the email piping to script in cpanel. Also in script i send a acknowledge mail to me to confirm whether the script works or not. But the script works fine and i have received the mail to my inbox. I got one more mail which indicates mail delivery system error. can anyone have solution for this. I really thanku very much if u give solution for this.

The error looks like given below


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/xxxx/public_html/xxxx/mail.php
generated by xxxxx.mydomain.com

The following text was generated during the delivery attempt:

------ pipe to |/home/xxxx/public_html/xxxxx/mail.php
generated by xxx@mydomain.com ------

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

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

Return-path: <xxxx@mydomain.com>
Received: from [61.247.255.207] (helo=system28)
by blackbox.networkoneit.com with smtp (Exim 4.52)
id 1GQ7pr-0008IO-HO
for xxx@mydomain.com; Wed, 20 Sep 2006 12:34:20 -0700
Message-ID: <015801c6dcea$bbaaaaa0$4e01a8c0@system28>
From: "Mahendran" <xxx@mydomain.com>
To: <xxx@mydomain.com>
Subject: hi
Date: Thu, 21 Sep 2006 00:56:51 +0530
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="----=_NextPart_000_0155_01C6DD18.D3350A20"
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 6.00.2600.0000
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000

This is a multi-part message in MIME format.

------=_NextPart_000_0155_01C6DD18.D3350A20
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable




------=_NextPart_000_0155_01C6DD18.D3350A20
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2600.0" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV></BODY></HTML>

------=_NextPart_000_0155_01C6DD18.D3350A20--
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 1,075
Reputation: digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice 
Solved Threads: 66
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Veteran Poster

Re: Email piping to script problem

 
0
  #2
Sep 20th, 2006
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
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 54
Reputation: mahe4us is an unknown quantity at this point 
Solved Threads: 0
mahe4us's Avatar
mahe4us mahe4us is offline Offline
Junior Poster in Training

Re: Email piping to script problem

 
0
  #3
Sep 20th, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 1,075
Reputation: digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice 
Solved Threads: 66
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Veteran Poster

Re: Email piping to script problem

 
0
  #4
Sep 20th, 2006
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?
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 54
Reputation: mahe4us is an unknown quantity at this point 
Solved Threads: 0
mahe4us's Avatar
mahe4us mahe4us is offline Offline
Junior Poster in Training

Re: Email piping to script problem

 
0
  #5
Sep 20th, 2006
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<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];
}
} else {
// not a header, but message
$message .= $lines[$i]."\n";
}

if (trim($lines[$i])=="") {
// empty line, header section has ended
$splittingheaders = false;
}
}
mail('mydomain@mydomain.com', 'email received', $email, 'from: Server');
// clean the output
ob_end_clean();
?>
----------------------
I think my server is running php through apache module. But iam not sure because i dont know how to find it.
Thanks..
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 1,075
Reputation: digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice 
Solved Threads: 66
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Veteran Poster

Re: Email piping to script problem

 
0
  #6
Sep 21st, 2006
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.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 54
Reputation: mahe4us is an unknown quantity at this point 
Solved Threads: 0
mahe4us's Avatar
mahe4us mahe4us is offline Offline
Junior Poster in Training

Re: Email piping to script problem

 
0
  #7
Sep 21st, 2006
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..
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 1,075
Reputation: digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice 
Solved Threads: 66
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Veteran Poster

Re: Email piping to script problem

 
0
  #8
Sep 21st, 2006
Originally Posted by mahe4us View Post
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..
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 54
Reputation: mahe4us is an unknown quantity at this point 
Solved Threads: 0
mahe4us's Avatar
mahe4us mahe4us is offline Offline
Junior Poster in Training

Re: Email piping to script problem

 
0
  #9
Sep 22nd, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 1,075
Reputation: digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice digital-ether is just really nice 
Solved Threads: 66
Moderator
digital-ether's Avatar
digital-ether digital-ether is offline Offline
Veteran Poster

Re: Email piping to script problem

 
0
  #10
Sep 22nd, 2006
Originally Posted by mahe4us View Post
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.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC