开发者

Handling Incoming Mail to Multiple Recipients in PHP

开发者 https://www.devze.com 2022-12-25 16:26 出处:网络
Alright, this may take a moment or two to explain: I\'m working on creating an Email<>SMS Bridge (like Teleflip).I have a few set parameters to work in:

Alright, this may take a moment or two to explain:

I'm working on creating an Email<>SMS Bridge (like Teleflip). I have a few set parameters to work in:

  • Dreamhost Webhosting
  • PHP 5 (without PEAR)
  • Postfix
  • MySQL (If Needed)

What I have right now, is a catch-al开发者_如何学Cl email address that forwards the email sent to a shell account. The shell account in turn forwards it to my PHP script.

The PHP script reads it, strips a few Email Headers in an effort to make sure it sends properly, then forwards it to the number specified as the recipient. 5551234567@sms.bridge.gvoms.com of course sends an SMS to +1 (555) 123-4567.

This works really well, as I am parsing the To field and grabbing just the email address it is sending to. However, what I realized that I did not account for is multiple recipients. For example, an email sent to both 5551234567 and 1235554567 (using the To line, the CC line, or any combination of those).

The way email works of course, is I get two emails received, end up parsing each of them separately, and 5551234567 ends up getting the same message twice.

What is the best way to handle this situation, so that each number specified in TO and CC can get one copy of the message.

In addition, though I doubt its possible: Is there a way to handle BCC the same way?


If you check the headers of the mail, you should find a Message-ID field (according to RFC2822 - section 3.6.4). So you could test if you have already sent an SMS for a mail with the same Message-ID & phone number to prevent sending the same message to the same number twice.


Why not use something like imap to check the catch-all mailbox, loop through the messages and then delete them once finished? That way you don't need to forward them to a seperate account.


Stupid dirty solution: parse all recipients from the mail, then send them SMS, then put em all into temporary table with md5 of message text. And check all incoming mails against this table.


Although wimvds had the best answer here, I found out elsewhere that Dreamhost includes a "X-DH-Original-To" header in the way I'm running it through the system. Using this, I'm able to send to each number individually upon receipt of the email without checking it against a database. This should also work with Blind Carbon Copy (I don't know the specifics of how email works enough to tell you how that works).

0

精彩评论

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