0

我花了几个小时,但我终于想出了如何使用 cPanel X3 将邮件发送到我的 PHP 脚本。

实际的解析脚本只是我设置的一个测试脚本,它在执行时会通过电子邮件发送给我。

#!/usr/local/bin/php -q
<?php
$headers = "From: test@email.com";
$to = "myemail@gmail.com";
$subject = "Recieved";
$body = "Message recieved.";
$mail = mail($to, $subject, $body, $headers);

上面的脚本正确执行并接收数据,即使它正在接收邮件,它也会发回以下内容:

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/PATH/TO/SCRIPT/parse.php
   generated by test@email.com

The following text was generated during the delivery attempt:

------ pipe to |/home/PATH/TO/SCRIPT/parse.ph
  generated by test@email.com ------

PHP Warning:  Module 'PDO' already loaded in Unknown on line 0
PHP Warning:  Module 'pdo_sqlite' already loaded in Unknown on line 0
PHP Warning:  Module 'SQLite' already loaded in Unknown on line 0
PHP Warning:  Module 'pdo_mysql' already loaded in Unknown on line 0

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

Return-path: <myemail@gmail.com>
Received: from mail-fx0-f44.google.com ([209.85.161.44])
       by my.server.com with esmtps (TLSv1:RC4-SHA:128)
       (Exim 4.69)
       (envelope-from <myemail@gmail.com>)
       id 1QpAdr-0008UY-MO
       for test@email.com; Thu, 04 Aug 2011 22:00:07 -0500
Received: by fxe6 with SMTP id 6so2641925fxe.3
       for <test@email.com>; Thu, 04 Aug 2011 20:00:04 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
       d=gmail.com; s=gamma;
       h=mime-version:from:date:message-id:subject:to:content-type;
       bh=gqxzpu6OEZTUs6uTT1G+NLaRvZh0HIOfcrOh1KtUuqw=;
       b=ICOQ1YpNQZKXxAB5DCguFui6aCSqg9wMDaj8S+1iuNkJQhGL8otqT8zRdRU8i+dngU
        +KjDbSPNLdt52PGLqbz4v48MKWUCeaTo/xwa4Pftix6d63x6yqwU4/Hy9ZG9dhNiVHYM
        goSQb+InqzTgw3msyWMsw75Mddwh/HK4I8fv0=
Received: by 10.204.151.216 with SMTP id d24mr532167bkw.304.1312513204131;
 Thu, 04 Aug 2011 20:00:04 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.204.23.196 with HTTP; Thu, 4 Aug 2011 19:59:44 -0700 (PDT)
From: myemail@gmail.com
Date: Thu, 4 Aug 2011 22:59:44 -0400
Message-ID: <CAHxz2PpNoNWRakeP2JoN8cdmPfz=HrYd5N2vZ4aqb9E_vLiUjw@mail.gmail.com>
Subject: Hahahahha
To: test@email.com
Content-Type: multipart/alternative; boundary=0015175dd9cc4b987d04a9b94b71

--0015175dd9cc4b987d04a9b94b71
Content-Type: text/plain; charset=ISO-8859-1

awda asd asdqwd a xzccz

--0015175dd9cc4b987d04a9b94b71
Content-Type: text/html; charset=ISO-8859-1

awda asd asdqwd a xzccz

--0015175dd9cc4b987d04a9b94b71--    

这是我在 cPanel 中使用的路径:

|php -q -n /PATH/TO/SCRIPT/parse.php

如果正在执行脚本,为什么我仍然从我的服务器收到该错误?

编辑:我想出了问题所在。我的 php.ini 文件设置不正确。以下是重复的:

extension=pdo.so
extension=pdo_sqlite.so
extension=sqlite.so
extension=pdo_mysql.so
4

3 回答 3

2

The reason for the "error mail" is that the MTA thinks there was an error if the executed program has written something on stdout or stderr (I'm not shure) - this is what php does when it is emitting a warning.

You could try to suppress those warnings by setting error_reporting:

|php -n -d error_reporting=E_ERROR /PATH/TO/SCRIPT/parse.php

If that doesn't work then try to eliminate all output:

|php -d display_errors=off -d display_startup_errors=off -d error_log=/dev/null -n /PATH/TO/SCRIPT/parse.php

But that way you won't see any errors like syntax errors which may be not desired.

于 2011-08-05T05:20:03.913 回答
0

The only issue I see is the $headers = "From: test@email.com"; should be $headers = "From: test@email.com\r\n";

于 2011-08-05T03:37:28.983 回答
0

上面的脚本正确执行并接收数据,即使它正在接收邮件

? 您显示的脚本不接收它只发送它们的电子邮件。

为什么我仍然收到该错误

哪个错误?由于配置错误导致 PHP 错误 - 但这些并不会阻止脚本运行。这些可能会根据 MDA 生成反向散射。还有无法投递的消息 - 这是您的 Exim 配置的问题。

您的接收脚本也会在读取 STDIN 管道之前退出并关闭它。真的,您应该阅读 EOF 并以显式返回码退出(0 表示成功)

于 2011-08-05T09:46:13.710 回答