簡體   English   中英

如果使用管道到php腳本方法傳遞電子郵件失敗時發生某些事情,如何更改MTA返回錯誤

[英]How to Change the MTA return error if something happend when delivery email failed using pipe to php script method

我使用WHM / Cpanel

我使用管道技術將收入電子郵件轉發到PHP腳本,並且很好。 但是在工作時如果發生任何錯誤,例如管道下面的消息將返回給電子郵件發件人

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

請注意,我從Cpanel制作電子郵件,發送電子郵件至support@somecompany.net | /home/someuser/public_htmk/pipe.php

下面的PHP腳本沒有錯誤:)但是我定義了文件的路徑以產生錯誤,因為它應該是public_html而不是public_htmk但我犯了這個錯誤,以顯示返回給電子郵件發件人的錯誤消息。

所以無論如何要控制這個返回的消息或禁用它。 例如,改變它是否發送我們正在運行的php文件的物理地址至少管道電子郵件?

順便說一下,我正在使用

WHM / Cpanel Dovecot PHP

這是管道腳本的示例(此腳本沒有任何錯誤)

#!/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 . '"');

我正在尋找自定義或禁用返回郵件的返回消息,當發送電子郵件到腳本時發生一些錯誤。

有任何想法嗎?

如果你不堅持在管道定義中加入麻煩的代碼,你可以在php腳本周圍使用shell腳本包裝器,比如

#!/bin/bash
/home/someuser/public_htmk/pipe.php >&/home/someuser/pipe.errors.log || true

並在管道定義中使用它。

在某些情況下,這可能會對您的問題有所幫助,但如果啟用了display_errors則腳本中的錯誤消息可能會觸發您的php腳本的否定響應,從而導致消息反彈。 如果將其關閉,則不會輸出任何錯誤或將其返回給MTA。

如果由於某種原因你有一個致命的錯誤,如解析錯誤,那么這可能沒有幫助。

我不確定您是否有任何方法可以控制返回郵件的內容,但您可能會阻止它或嘗試將郵件返回給它。

exit(0);可能會有所幫助exit(0); 在電子郵件處理器的末尾指示成功,因此如果您的腳本能夠到達終點,它將成功退出並可能阻止MTA發送返回消息。

我不確定這是否有所作為,但它可能有助於檢查打開php:// stdin是否成功,因為某些原因它可能會失敗並且如果你無法讀取它,那么終止腳本。

要嘗試控制輸出,如果檢測到錯誤,請嘗試回顯消息或使用exit("status message");

在您收到的返回消息中,它是否包含從PHP輸出的錯誤消息或失敗的原因?

我有同樣的問題,我通過在root / etc文件夾中添加一個名為exim.conf的文件來解決它它對我有用以下是該文件的內容希望它也能幫助其他人!

# 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}}"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM