如果使用管道到php脚本方法传递电子邮件失败时发生某些事情,如何更改MTA返回错误
I using WHM/Cpanel
Im using the pipe technique to forward the income emails to php script and everthing fine. but while working if any error happend while piping the following msg for example will returned to the email sender
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/someuser/public_htmk/pipe.php
generated by support@somecompany.net
local delivery failed
Please note that I make the pipe from Cpanel for the email support@somecompany.net|/home/someuser/public_htmk/pipe.php
the php script below does not have error :) but I define the path of the file to make an error because it should be public_html not public_htmk but I make this error to show you the error message which returned to the email sender.
So is there anyway to control of this returned message or disable it . for example change it or not to send the physical address of the php file that we are running to pipe the email atleast?
BTW I'm using
WHM/Cpanel Dovecot PHP
and this is a sample of the pipe script (this script does not have any error)
#!/usr/local/bin/php -q
<?php
// read from stdin
$emg_stdf = fopen("php://stdin", "r");
$email = "";
while (!feof($emg_stdf))
{
$emg_orgemailmsg .= fread($emg_stdf, 1024);
}
fclose($emg_stdf);
mail('me@example.org','From my email pipe!','"' . $emg_orgemailmsg . '"');
I'm looking to customize or disable the return msg which returned to the email sender when some error happened when piping email to a script.
any ideas?
我使用WHM / Cpanel p>
我使用管道技术转发 收入电子邮件发送到PHP脚本并且正常。 但是在工作时如果发生任何错误,而管道下面的msg例如将返回给电子邮件发件人 p>
此消息是由 邮件传送软件。
您发送的邮件无法传送给一个或多个收件人。 这是一个永久性错误。 以下地址失败:
管道到| /home/someuser/public_htmk/pipe.php
由support@somecompany.net生成
本地传递失败
code> pre> \ n
请注意我从Cpanel制作电子邮件,发送电子邮件至support@somecompany.net | /home/someuser/public_htmk/pipe.php strong> p>
下面的PHP脚本没有错误:)但是我定义了文件的路径以产生错误,因为它应该是public_html而不是public_htmk但我犯了这个错误,以显示返回给电子邮件发件人的错误消息。 / p>
所以无论如何都要控制这个返回的消息或禁用它。 例如,改变它是否发送我们正在运行的php文件的物理地址至少管道电子邮件? p>
BTW我正在使用 p>
WHM / Cpanel
Dovecot
PHP p>
这是管道脚本的示例(此脚本没有任何错误) p>
#!/ usr / local / bin / php -q
&lt;?php
//从stdin读取
$ emg_stdf = fopen(“php:// stdin”,“r”);
$ email =“”;
while(!feof($ emg_stdf))
{
$ emg_orgemailmsg。= fread($ emg_stdf,1024);
}
nclclose($ emg_stdf);
mail('me @ example.org','来自我的电子邮件管道!','''。$ emg_orgemailmsg。'“');
code> pre>
我希望自定义或 当电子邮件发送到脚本时发生错误时,禁用返回给邮件发件人的返回消息。 p>
任何想法? p>
div>
If you do not insist on putting troublesome code in the pipe definition, you can use the shell script wrapper around your php
script, something like
#!/bin/bash
/home/someuser/public_htmk/pipe.php >&/home/someuser/pipe.errors.log || true
and use it in your pipe definition.
This may help your problem in some cases, but if display_errors
is turned on, an error message in your script may trigger a negative response from your php script which causes the message to bounce. If you turn it off, then no errors would be output or returned to the MTA.
If you have a fatal error such as a parse error for some reason, then that may not help.
I'm not sure you have any way to control the content of the returned message, but you could possibly prevent it or try to get a message back to it.
It may help to put exit(0);
at the end of the email processor to indicate success, so if your script is able to reach the end it exits successfully and may prevent the MTA from sending the return message.
I'm not sure if this makes a difference, but it may help to check if opening php://stdin was successful on the off chance that it could fail for some reason and if you can't read it, then terminate the script.
To try to control the output, if you detect an error, try echo'ing a message or using exit("status message");
In the return messages you get does it ever contain error messages output from PHP or a reason for failure?
I had the same problem and I solved it by adding a file named exim.conf in root/etc folder It worked for me Following are the contents of that file Hope it will help others too!
# This transport is used for handling pipe deliveries generated by alias
# or .forward files. If the pipe generates any standard output, it is returned
# to the sender of the message as a delivery error. Set return_fail_output
# instead of return_output if you want this to happen only when the pipe fails
# to complete normally. You can set different transports for aliases and
# forwards if you want to - see the references to address_pipe in the directors
# section below.
address_pipe:
driver = pipe
return_fail_output
virtual_address_pipe:
driver = pipe
group = nobody
return_fail_output
user = "${lookup{$domain}lsearch* {/etc/virtual/domainowners}{$value}}"