gpt4 book ai didi

php - 电子邮件管道到 PHP 脚本并转发到另一封电子邮件

转载 作者:搜寻专家 更新时间:2023-10-31 21:27:06 25 4
gpt4 key购买 nike

我正在尝试编写一个脚本,用于将电子邮件通过管道发送到它,然后转发到另一个具有不同“发件人”字段的电子邮件地址

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

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

// initialize variable which will assigned later on
$from = emailFrom@example.com;
$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( "emailTo@example.com", $subject,$message, $from );

?>

此脚本让我们收到退回的电子邮件,其中包含递送失败消息“本地递送失败”。

我做错了什么?

最佳答案

您需要验证它是否正确解析传入消息。在您的 mail() 命令之后添加此行以验证脚本的输出:

echo "Subject:".$subject."\nFrom:".$from."\nMessage:".$message;

然后从命令行向脚本传递一封测试电子邮件并观察屏幕。有些东西可能没有被正确解析。

关于php - 电子邮件管道到 PHP 脚本并转发到另一封电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34441694/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com