Page 1 of 1
Can emails come into a PHP / SQL database?
Posted: Wed Nov 20, 2013 5:02 am
by simonmlewis
Hi.
We need to collate emails that are coming in, into PHP and a database. So we can collate email addresses.
Facebook does it - you email
name@facebook.com and it will go into your Messages on your Facebook account.
I assume it's done with something else in the email address - but how??
Re: Can emails come into a PHP / SQL database?
Posted: Wed Nov 20, 2013 12:35 pm
by Eric!
Email is just text. You can process it however you want. There are several ways to access a mailbox and extract the text using PHP. I prefer using the
IMAP functions. This allows you to access mail on remote servers and is more portable code.
But in the old-school simplest way: you could also setup an email pipe for a specific email address (like
help@domain.com) on your server which tells your mail server to send the email directly to a PHP script. You can then parse everything directly.
Re: Can emails come into a PHP / SQL database?
Posted: Wed Nov 20, 2013 12:48 pm
by simonmlewis
My god I never knew that!
So do we have to tell the mail in Plesk 11 for a particular account to handle it differently? Basically, what is stopping Plesk (or whatever it is in the mail system) from handling it in the "default manner"?
I get that I could capture the data in the email, but how do I send the email to PHP (ie. domain.com/emailhandler.php) rather than the normal method?
Re: Can emails come into a PHP / SQL database?
Posted: Wed Nov 20, 2013 12:57 pm
by Eric!
You can either setup the IMAP functions to access whatever email account you've setup on the server, or you can setup the mail server (via Plesk) to pipe specific emails to a PHP file that parses it.
Your facebook.com example doesn't help me understand what you want to do. Do you expect to use just one incoming email address that you want to configure a mailbox for? Or do you want to have anything sent to your domain processed/saved?
Usually a mail server allows you to specify what to do with emails that have no accounts configured at that domain. You can then specify to pipe them to a PHP file. This way
any_random_address@yourdomain.com will be sent to the same script.
Re: Can emails come into a PHP / SQL database?
Posted: Wed Nov 20, 2013 1:03 pm
by simonmlewis
At the moment I'm not exactly sure. I think it's because we are getting those "email address doesn't exist" emails back, and would perhaps like them into a PHP script to query the email that failed and remove it from our database of emails.
But I'm not sure if these bounce backs are possible to collate via PHP.
Re: Can emails come into a PHP / SQL database?
Posted: Wed Nov 20, 2013 1:40 pm
by Eric!
Your mail server usually has the ability to process undeliverable mail in any way you want, including sending a bounce message or just ignoring/deleting it automatically...or passing it on to a PHP script to do something more complex with the undeliverable message.
Re: Can emails come into a PHP / SQL database?
Posted: Wed Nov 20, 2013 1:43 pm
by simonmlewis
We want to send that undeliverable (because it is
fred@fred.com for ex) to a PHP script, so we can collate the email in there and add it to our exclusion list.
What setting in Plesk should I be looking for, to set this up for a particular email? As I assume those come from a DAEMON address?
Re: Can emails come into a PHP / SQL database?
Posted: Wed Nov 20, 2013 1:53 pm
by Eric!
Talk to your host provider. You want to "pipe undeliverable messages to a php script". I don't know how to configure that in Plesk. If you used cPanel I could tell you.
Re: Can emails come into a PHP / SQL database?
Posted: Wed Nov 20, 2013 2:01 pm
by simonmlewis
Done that - out of interest, where is it in cPanel, as we have one site that does use cPanel so if I can see it, I might know where to find it in Plesk 11.
Re: Can emails come into a PHP / SQL database?
Posted: Wed Nov 20, 2013 4:02 pm
by Eric!
I'm not a fan of Plesk. I almost always end up doing everything over SSH.
cPanel:
http://docs.cpanel.net/twiki/bin/view/A ... lFowarders