开发者

Get all recipients from email To header in PHP (ZF is a bonus)

开发者 https://www.devze.com 2023-02-13 23:43 出处:网络
Is there a way to parse the recipients of an email with the Zend Framework? I\'m asking, because email TO headers can contain something like this:

Is there a way to parse the recipients of an email with the Zend Framework?

I'm asking, because email TO headers can contain something like this:

To: foo@bar.de, "Lastname, Firstname" <foo@bar.com>

So I can't just split on the comma. I didn't find a way to do this with the Zend Framework Mail class.

How do you do this? And is there a way to easily do this with the Zend开发者_StackOverflow中文版 Framework?


It seems ZF doesn't have that parser. This ticket is related, but no update since Jan 2010: http://framework.zend.com/issues/browse/ZF-3820

You can use imap_rfc822_parse_adrlist() with imap extension. http://php.net/manual/en/function.imap-rfc822-parse-adrlist.php

Or PEAR has a method to parse. http://pear.php.net/manual/en/package.mail.mail-rfc822.parseaddresslist.php


You can try with

  • str_getcsv — Parse a CSV string into an array

Example

print_r(
    str_getcsv(
        substr('To: foo@bar.de, "Lastname, Firstname" <foo@bar.com>', 3)
    )
);

Output (demo)

Array
(
    [0] => foo@bar.de
    [1] => Lastname, Firstname <foo@bar.com>
)

As for Zend_Mail, what does ZendMail::getRecipients() return? Or what are you using?


depends on how the other adresses are seperated, it is possible that you can split on "\n" and then split that up further

0

精彩评论

暂无评论...
验证码 换一张
取 消