[英]Getting an "Error in argument 1, char 3: option not found" when piping emails to a parser script
當我嘗試發送符合條件的電子郵件以將電子郵件傳輸到我的 php 腳本時,出現錯誤。 錯誤是:
pipe to |/home/**********/**********/script.php
generated by f1c8f287-02ea81a3-11a218b30839@**********.com
The following text was generated during the delivery attempt:
------ pipe to |/home/**********/**********/script.php
generated by f1c8f287-02ea81a3-11a218b30839@*********.com ------
Error in argument 1, char 3: option not found
Usage: php-cgi [-q] [-h] [-s] [-v] [-i] [-f <file>]
php-cgi <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.
Reporting-MTA: dns; srv28.hostserv.com
Action: failed
Final-Recipient: rfc822;|/home/**********/**********/script.php
Status: 5.0.0
我不想讓這個問題不必要地冗長......
這是我的完整 script.php 代碼以防萬一:
#!/usr/bin/php -q
<?php
// config
$dbHost = "********";
$dbUser = "********";
$dbPass = "********";
$dbName = "********";
//$conn = mysqli_connect($dbHost, $dbUser, $dbPass, $dbName) or die(mysqli_error($conn));
$notify= 'admin@*********.com'; // an email address required in case of errors
function mailRead($iKlimit = "")
{
// Purpose:
// Reads piped mail from STDIN
//
// Arguments:
// $iKlimit (integer, optional): specifies after how many kilobytes reading of mail should stop
// Defaults to 1024k if no value is specified
// A value of -1 will cause reading to continue until the entire message has been read
//
// Return value:
// A string containing the entire email, headers, body and all.
// Variable perparation
// Set default limit of 1024k if no limit has been specified
if ($iKlimit == "") {
$iKlimit = 1024;
}
// Error strings
$sErrorSTDINFail = "Error - failed to read mail from STDIN!";
// Attempt to connect to STDIN
$fp = fopen("php://stdin", "r");
// Failed to connect to STDIN? (shouldn't really happen)
if (!$fp) {
echo $sErrorSTDINFail;
exit();
}
// Create empty string for storing message
$sEmail = "";
// Read message up until limit (if any)
if ($iKlimit == -1) {
while (!feof($fp)) {
$sEmail .= fread($fp, 1024);
}
} else {
while (!feof($fp) && $i_limit < $iKlimit) {
$sEmail .= fread($fp, 1024);
$i_limit++;
}
}
// Close connection to STDIN
fclose($fp);
// Return message
return $sEmail;
}
// call function
$email = mailRead();
// handle email
$lines = explode("\n", $email);
// empty vars
$from = "";
$subject = "";
$headers = "";
$message = "";
$splittingheaders = true;
for ($i=0; $i < count($lines); $i++) {
if ($splittingheaders) {
// this is a header
$headers .= $lines[$i]."\n";
// look out for special headers
if (preg_match("/^Subject: (.*)/", $lines[$i], $matches)) {
$subject = $matches[1];
}
if (preg_match("/^From: (.*)/", $lines[$i], $matches)) {
$from = $matches[1];
}
if (preg_match("/^To: (.*)/", $lines[$i], $matches)) {
$to = $matches[1];
}
} else {
// not a header, but message
$message .= $lines[$i]."\n";
}
if (trim($lines[$i])=="") {
// empty line, header section has ended
$splittingheaders = false;
}
}
if ($conn = mysqli_connect($dbHost,$dbUser,$dbPass)) {
if(!mysqli_select_db($dbName,$conn))
mail($email,'Email Logger Error',"There was an error selecting the email logger database.\n\n".mysqli_error());
$from = mysqli_real_escape_string($from);
$to = mysqli_real_escape_string($to);
$subject = mysqli_real_escape_string($subject);
$headers = mysqli_real_escape_string($headers);
$message = mysqli_real_escape_string($message);
$email = mysqli_real_escape_string($email);
$result = mysqli_query("INSERT INTO email_log (`to`,`from`,`subject`,`headers`,`message`,`source`) VALUES('$to','$from','$subject','$headers','$message','$email')");
if (mysqli_affected_rows() == 0)
mail($notify,'Email Logger Error',"There was an error inserting into the email logger database.\n\n".mysqli_error());
} else {
mail($notify,'Email Logger Error',"There was an error connecting the email logger database.\n\n".mysqli_error());
}
?>
我遵循了這些規則,它們受到了檢查:
文件權限(及其目錄)設置為 0755
通過 cPanel 上傳。 該文件應為 ascii 格式而不是二進制格式(我不知道如何檢查)
在 php 標簽和 hashbang 之前/之后沒有空格/換行符
我查看並嘗試了這些類似問題的答案,但沒有解決我得到的錯誤:
其中包括 cPanel 論壇和其他資源。
此問題的解決方案是確保為 Unix 保存腳本的行尾。 如果您使用的是 Windows,請檢查您的文本編輯器用於保存行尾的默認設置。 相關問題證明在處理這個問題時很有用, How do configure sublime to always convert to unix line endings on save?
對於 Sublime Text 3,我只是更改了行尾格式(菜單 > 視圖 > 行尾 > Unix)並保存了文件。 電子郵件解析器現在可以正常工作。
這個出色的解決方案歸功於 Triplee。 對於未來的讀者,如果您是 Windows 用戶,一般故障排除論壇會提到無關的回車符,但不會提及將文本格式化為 Unix 行結尾的任何內容。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.