Handling incoming mail to multiple recipients in PHP

Well, this may take some time to explain:

I am working on creating an Email <> SMS bridge (e.g. Teleflip). I have some given parameters for work:

  • Web Hosting Dreamhost
  • PHP 5 (without PEAR)
  • Postfix
  • MySQL (if necessary)

Now I have a full email address that sends the email sent to the shell account. The shell account, in turn, redirects it to my PHP script.

The PHP script reads it, breaks several email headers to make sure it is sent correctly, and then forwards it to the number specified as the recipient. 5551234567@sms.bridge.gvoms.com , of course, sends SMS to +1 (555) 123-4567.

This works very well, as I parse the To field and grab only the email address to which it sends. However, I realized that I did not account for several recipients. For example, an email sent to both 5551234567 and 1235554567 (using the To line, the CC line, or any combination thereof).

How email works, I get two received emails, eventually parsing each one separately, and 5551234567 ends up getting the same email twice.

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

Also, although I doubt its feasibility: is there a way to handle BCC in the same way?

+4
source share
4 answers

Although wimvds had a better answer, I found out elsewhere that Dreamhost includes the β€œX-DH-Original-To” header in how I run it through the system. Using this, I can send to each number individually after receiving email without checking it against the database. This should also work with Blind Carbon Copy (I don't know the specifics of how email works enough to tell you how it works).

0
source

If you check the mail headers, you should find the Message-ID field (according to RFC2822 - section 3.6.4 ), so you can check if you have already sent an SMS message for mail with the same identifier and phone number, to prevent sending the same message to the same number at the same time.

+2
source

Why not use something like imap to check the catch-all mailbox, skip messages, and then delete them upon completion? Thus, you do not need to forward them to a separate account.

+1
source

Silly dirty solution: analyze all the recipients from the mail, then send them an SMS, then put them in a temporary table with md5 message text. And check all incoming letters on this table.

0
source

Source: https://habr.com/ru/post/1305545/


All Articles