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: <[EMAIL="015801c6dcea$bbaaaaa0$4e01a8c0@system28"]015801c6dcea$bbaaaaa0$4e01a8c0@system28[/EMAIL]>
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--

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

// 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();

?>

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

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

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?

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..

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.

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..

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:

mail('mydomain@mydomain.com', 'email received', $email, 'from: Server');

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..

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

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.

Hi to everyone,

Once again I come back with this issue after a long time. In my previous post I mentioned a bounce mail come to my mail address. It has solved by upgrading the zend optimizer in the server. But I have one more issue with this if i sent a mail to the server then the server redirected the mail to the php script. It works fine. But the mail which i got in my inbox contains some invalid html contents. Please anyone help me how to resolve this. Thanks for all.

The unwanted html contents are given below.
This is a multi-part message in MIME format.

------=_NextPart_000_0110_01C6F00E.2DD4FFA0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi,

this is a test mail.

------=_NextPart_000_0110_01C6F00E.2DD4FFA0
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>Hi,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>this is a test =
mail.</FONT></DIV></BODY></HTML>

------=_NextPart_000_0110_01C6F00E.2DD4FFA0--

1. Go to Cpanel and in setting a Catch-all email account,choose option to pipe mail to script, enter path in the following way:

public_html/myfolder/pipescript.php

2. Go to your parseall script and do what you want with the content of the mail). with this at the very top

#!/usr/local/bin/php -q
<?php
...
?>

3. After parsing email, on your XP computer, remove all linefeeds and line returns with Dos2unix by going to cmd and inputting:

dos2unix pipescript.php

4. Upload the unixfied file.

5. Make executable by changing permissions to 755 (using chmod on unix)

And you're good to go.

Note: Make sure there is no print or echo statement in the script, no output or warnings otherwise the sender of the email will receive an error message like the mail wasn't received.

Thank you Lord for this.

Hi to everyone,

Once again I come back with this issue after a long time. In my previous post I mentioned a bounce mail come to my mail address. It has solved by upgrading the zend optimizer in the server. But I have one more issue with this if i sent a mail to the server then the server redirected the mail to the php script. It works fine. But the mail which i got in my inbox contains some invalid html contents. Please anyone help me how to resolve this. Thanks for all.

The unwanted html contents are given below.
This is a multi-part message in MIME format.

------=_NextPart_000_0110_01C6F00E.2DD4FFA0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi,

this is a test mail.

------=_NextPart_000_0110_01C6F00E.2DD4FFA0
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>Hi,</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>this is a test =
mail.</FONT></DIV></BODY></HTML>

------=_NextPart_000_0110_01C6F00E.2DD4FFA0--

It sounds like you may be having some difficulty parsing your email into different parts such as the plain text, HTML, and attachment parts. A very good script for doing this is Pear's Mail_mimeDecode library.

http://pear.php.net/package/Mail_mimeDecode/redirected

There are also some remotely hosted services that will accept a forwarded email and then POST the parsed contents to your script. This can save you the trouble of needing to do the parsing on your side. Some good services for doing this are:

http://mailhooks.com
http://smtp2web.com
http://mailnuggets.com

This article has been dead for over six months. Start a new discussion instead.