【问题标题】:Get Email that email was piped to获取电子邮件被传送到的电子邮件
【发布时间】:2011-01-06 18:58:23
【问题描述】:

我有一个从电子邮件管道调用的脚本。 所以有人给 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;
}
}
?>

我怎样才能得到它被发送到的电子邮件?在这种情况下,我想要 $to = 'abc@example.com'; 但 'abc' 可以是任何东西,所以我主要想要电子邮件地址中的用户名。

对不起,如果这没有意义或很笨,我是新手!

提前致谢。

【问题讨论】:

    标签: php email


    【解决方案1】:

    您正在寻找 Envelope-to 标头

    您可以编辑代码以包含preg_match("/^Envelop-to: (.*)/", $lines[$i], $matches)

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

    【讨论】:

    • 没有这样的东西......来源仅显示“(信封-来自 )”
    • 通过查看源码找到“To:”,所以你得到了√
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-08-02
    • 1970-01-01
    • 1970-01-01
    • 2012-07-02
    • 2014-05-30
    • 1970-01-01
    • 2016-11-30
    相关资源
    最近更新 更多