简体   繁体   English

PHP电子邮件管道错误

[英]PHP email piping error

I'm writing a php script to pipe email from a forward in my CPanel. 我正在编写一个php脚本,以从CPanel中的转发管​​道发送电子邮件。 I have found this script on the internet; 我已经在互联网上找到了这个脚本; I am trying to parse the email and send it back to myself for testing, but it instead returns this error: 我正在尝试解析电子邮件并将其发送回我自己进行测试,但它返回此错误:

The following text was generated during the delivery attempt:

------ pipe to |/home1/<account>/pipe.php
 generated by pipe@example.com ------

Error in argument 1, char 3: option not found <
Usage: php [-q] [-h] [-s] [-v] [-i] [-f <file>]
 php <file> [args...]
 -a Run interactively
 -b <address:port>|<port> Bind Path for external FASTCGI Server mode
 -C Do not chdir to the script's directory
 -c <path>|<file> Look for php.ini file in this directory
 -n No php.ini file will be used
 -d foo[=bar] Define INI entry foo with value 'bar'
 -e Generate extended information for debugger/profiler
 -f <file> Parse <file>. Implies `-q'
 -h This help
 -i PHP information
 -l Syntax check only (lint)
 -m Show compiled in modules
 -q Quiet-mode. Suppress HTTP Header output.
 -s Display colour syntax highlighted source.
 -v Version number
 -w Display source with stripped comments and whitespace.
 -z <file> Load Zend extension <file>.
 -T <count> Measure execution time of script repeated <count> times.

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

The script is below: 脚本如下:

#!/usr/bin/php -q
<?
$fd = fopen("php://stdin", "r");
$email = "";
while (!feof($fd)) {
    $email .= fread($fd, 1024);
}
fclose($fd);

//split the string into array of strings, each of the string represents a single line, received
$lines = explode("\n", $email_content);

// initialize variable which will assigned later on
$from = "";
$subject = "";
$headers = "";
$message = "";
$is_header = true;

//loop through each line
for ($i = 0; $i < count($lines); $i++) {
    if ($is_header) {
        // hear information. instead of main message body, all other information are here.
        $headers .= $lines[$i]."\n";

        // Split out the subject portion
        if (preg_match("/^Subject: (.*)/", $lines[$i], $matches)) {
            $subject = $matches[1];
        }
        //Split out the sender information portion
        if (preg_match("/^From: (.*)/", $lines[$i], $matches)) {
            $from = $matches[1];
        }
    } else {
        // content/main message body information
        $message .= $lines[$i]."\n";
    }
    if (trim($lines[$i])=="") {
        // empty line, header section has ended
        $is_header = false;
    }
}

mail("email@example.com", $subject, '"' . $message . . "\n\n\n" . $email . '"');

The permissions for the php file are 755. php文件的权限为755。

have you tried changing your second line to 您是否尝试过将第二行更改为

<?php

also make sure there's no extra spaces in first line 还要确保第一行没有多余的空格

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM