How do I handle incoming mail with PHP?

Started by chinmay.sahoo, 07-16-2016, 07:28:32

Previous topic - Next topic

chinmay.sahooTopic starter

You've already seen that sending mail with PHP is no problem. But what about dealing with incoming mail using PHP? If your site is hosted on a Linux system, you'll be happy to hear that with a little tuning, it's easy to have PHP to examine incoming email.

Solution
In this solution, I'll assume that you have your site hosted on a Linux-based system, that you have command prompt access to the server and are able to run PHP from the command prompt, and that you're using sendmail to handle email on the server. Phew! It's a long list of requirements, I know, but this fairly common configuration greatly simplifies matters.

First things first: you need to place a file called .forward in your home directory. Use a text editor to write the following to the file (all on one line):


TomClarke


If your host support the PHP IMAP functions, you can use it to loop through emails in an email account and insert them in the database.