【发布时间】: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' 可以是任何东西,所以我主要想要电子邮件地址中的用户名。
对不起,如果这没有意义或很笨,我是新手!
提前致谢。
【问题讨论】: