3

我正在使用这个库来解析我收到的电子邮件: http ://code.google.com/p/php-mime-mail-parser/

我安装了 Mailparse 扩展,一切都很好,但是当我这样做时:

echo $from = $Parser->getHeader('from');

它回显了name电子邮件发件人的地址,例如:John Smith,但我需要email电子邮件发件人的地址,例如john@smith.com

这也发生在:

echo $to = $Parser->getHeader('to');

而且我似乎找不到任何解决方案来获得这些,这里有什么帮助吗?谢谢在adnva

4

1 回答 1

4

您需要htmlspecialchars()在 to/from 上应用功能:

// You need to apply htmlspecialchars() function on to/from:
$from = htmlspecialchars($Parser->getHeader('from'));
$to = htmlspecialchars($Parser->getHeader('to'));

// the above code will give you something like:
// John Smith <john@smith.com>
// so to get the email address we need to use explode() function:

function get_email_address($input){
        $input = explode('&lt;', $input);
        $output = str_replace('&gt;', '', $input);
        $name = $output[0]; // THE NAME
        $email = $output[1]; // THE EMAIL ADDRESS
        return $email;
}

$from = htmlspecialchars($Parser->getHeader('from'));
echo $from = get_email_address($from); // NOW THIS IS THE EMAIL

$to = htmlspecialchars($Parser->getHeader('to'));
echo $from = get_email_address($to) // NOW THIS IS THE EMAIL
于 2013-12-30T16:48:31.720 回答