3

I'm trying to do automate stuff with PHP and IMAP.

I assign a key to every elements I have in my database (e.g. issue tickets) so people can send mails with attachments to myaccount+key@mycompany.com. With PHP and IMAP I get the "key" and then assign the body and attachment with the element which has the "key" assigned.

This works wells except when some people wants to redirect automatically a generic e-mail account to the assigned e-mail address.

So, for instance, I have:

Original sender: user1@example.com
Generic e-mail address: issues@alpha.com
Assigned key: 123456

They configure to redirect issues@alpha.com to myaccount+123456@mycompany.com

When I examine myaccount@mycompany.com and get the mail, with PHP and IMAP I get the sender, but is issues@alpha.com and I want to get myaccount+123456@mycompany.com in order to determine where I must put the information.

I try all with PHP IMAP functions but I get nothing although reading the original mail from gmail, I show a "Delivered-To" field where is stored the myaccount+123456@mycompany.com.

How can I get the delivered-to field?

Thanks a lot.

Regards!

4

1 回答 1

3

你可以使用这个php函数

imap_fetchheader ( resource $imap_stream , int $msg_number [, int $options = 0 ] )

但这将返回电子邮件的整个标题。

这是一个示例,我如何解析 Delivered-To:

  • $this->connection 连接到 imap
  • $i 是消息数(用于测试,您可以使用 1)

例子

$headers = explode("\n", imap_fetchheader($this->connection, $i));
$head = array();
foreach($headers as $key => $header) {
    $data = explode(":", $header);
    if( count($data) == 2 && !isset($head[$data[0]])) {
        $head[trim($data[0])] = trim($data[1]);
    }
}

$head['Delivered-To'] 将是您的地址。

于 2013-09-02T14:17:58.560 回答