Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 获取通过管道发送到的电子邮件_Php_Email - Fatal编程技术网

Php 获取通过管道发送到的电子邮件

Php 获取通过管道发送到的电子邮件,php,email,Php,Email,我有一个从电子邮件管道调用的脚本。 所以有人发电子邮件abc@example.com,然后它就到了这里 #!/usr/bin/php -q <?php // read from stdin $fd = fopen("php://stdin", "r"); $email = ""; while (!feof($fd)) { $email .= fread($fd, 1024); } fclose($fd); // handle email $lines = explode("\n", $em

我有一个从电子邮件管道调用的脚本。 所以有人发电子邮件abc@example.com,然后它就到了这里

#!/usr/bin/php -q
<?php
// read from stdin
$fd = fopen("php://stdin", "r");
$email = "";
while (!feof($fd)) {
$email .= fread($fd, 1024);
}
fclose($fd);
// 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];
}
} else {
// not a header, but message
$message .= $lines[$i]."\n";
}
if (trim($lines[$i])=="") {
// empty line, header section has ended
$splittingheaders = false;
}
}
?>
我怎样才能获得它发送到的电子邮件?在这种情况下,我想要$abc@example.com'; 但是“abc”可以是任何东西,所以我主要希望用户名来自电子邮件地址

对不起,如果这不合理或是没有意义,我是新手


提前谢谢。

您正在寻找要打印的信封

您可以编辑代码,将preg_match/^envelope to:.*/,$lines[$i],$matches包括在内


查看发送给您的电子邮件的源代码是一个很好的资源。

您正在寻找要发送的信封标题

您可以编辑代码,将preg_match/^envelope to:.*/,$lines[$i],$matches包括在内


查看发送给您的电子邮件的源代码是一个很好的资源。

没有这样的事情。。。源显示信封从onlyfound到:通过查看源,您可以获得√没有这样的事。。。源显示信封从onlyfound到:通过查看源,您可以获得√