我正在开发一个需要将电子邮件发送到php脚本的应用程序,该脚本将读取入站电子邮件并根据内容处理它。我已经根据需要将文件夹和脚本设置为chmod 755,并且域的默认catch-all电子邮件是管道到脚本。这是基本的测试脚本:
#!/usr/local/bin/php
<?php
// ^ yes, that's the proper path to php
// read the email
$email = "";
$fp = fopen("php://stdin", "r");
while (!feof($fp)) {
$email .= fread($fp, 1024);
}
fclose($fp);
// for testing put the email into a file on the server.
$t = microtime(true);
file_put_contents('/home/MYACCOUNT/public_html/THEDOMAIN.com/pipe/email-' . $t . '.txt', $email);
// email me a copy of the inbound email
$email = wordwrap($email, 70, "\r\n");
$to = 'MYEMAIL@gmail.com';
$subject = 'You Sent a Test Email';
$headers = 'From: info@THEDOMAIN.com' . "\r\n" .
'Reply-To: info@THEDOMAIN.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
return mail($to, $subject, $email, $headers);
?>
这是我得到的错误:
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/MYACCOUNT/public_html/THEDOMAIN.com/pipe/send-test.php
generated by test@THEDOMAIN.com
local delivery failed
The following text was generated during the delivery attempt:
------ pipe to |/home/MYACCOUNT/public_html/THEDOMAIN.com/pipe/send-test.php
generated by test@THEDOMAIN.com ------
Could not exec '/home/MYACCOUNT/public_html/THEDOMAIN.com/pipe/send-test.php'
Action: failed
Final-Recipient: rfc822;|/home/MYACCOUNT/public_html/THEDOMAIN.com/pipe/send-test.php
Status: 5.0.0
我有其他能够处理脚本电子邮件的应用程序,所以我对可能发生的事情感到茫然。任何帮助将不胜感激。谢谢!
答案 0 :(得分:0)
检查文件权限(及其目录)设置为0755,文件应为ascii格式,而不是二进制
php标签和hashbang之前/之后没有空格/换行符