Closed GoogleCodeExporter closed 9 years ago
[deleted comment]
You must parse the address with mailparse_rfc822_parse_addresses.
public function getHeader($name) {
if (isset($this->parts[1])) {
$headers = $this->getPartHeaders($this->parts[1]);
if (isset($headers[$name])) {
if ($name == "from" || $name == "to") {
//parse email address
$part_email = mailparse_rfc822_parse_addresses($headers[$name]);
$address = "";
foreach ($part_email as $value)
{
if ($address != "")
$address.=", ";
$address .= htmlspecialchars($value['display']." <".$value['address'].">");
}
return $address;
}
else
return $headers[$name];
}
} else {
throw new Exception('MimeMailParser::setPath() or MimeMailParser::setText() must be called before retrieving email headers.');
}
return false;
}
Original comment by palvoel...@gmail.com
on 27 Aug 2010 at 5:30
jbog91, I'm not able to reproduce the problem you're seeing. I've taken your
two test files and run them and I get :
{{{
<pre>Array
(
[to] => to@another-example.com
[from] => Jay <from@example.com>
[subject] => test
[body] => testing testing do da do de do
)
</pre>
}}}
The "to and "from" values are captured correctly. I'm not seeing it "just
return the name". I'm getting back "[from] => Jay <from@example.com>"
Palvoelgyi is correct that if you want to take the values returned and parse
them into an array of their components, mailparse_rfc822_parse_addresses is the
function to use.
I've done that in your test and it provides what you're looking for.
I think we probably shouldn't change the behavior within php-mime-mail-parser
to provide an array of the email address components back instead of the string
since it'll probably break existing installations.
I'll mark this as WontFix, but let me know if you're still having trouble.
Original comment by gene.wood.temp
on 22 Oct 2010 at 4:51
Original issue reported on code.google.com by
jbog91
on 31 Oct 2009 at 4:08Attachments: