1

I got requirement to build a email box. In which I am going to save incomming and outgoing emails in/out of mysql database. How can I write a php script so my all emails will arrive in my mysql database?

Developer
  • 25,073
  • 20
  • 81
  • 128

1 Answers1

0

PHP is a web scripting language primarily designed for building web applications. Your requirement seems to be more of a system application.

It's hard to determine what you will need to do because all mail servers offer different apis and storage options. I would suggest, if possible, you tell your mail server to store the messages on the file system and then use something along the lines of Python, C#, or C++ to watch the directory and then parse out the emails once they are added.

Note: You can still use PHP in this manner through calling the script with php.exe, but I really wouldn't recommend it. There are many better languages out there for doing what you are trying to do.

You can then schedule your application to check file modification times and then if a file has been added since your last process run you can parse the email and use a database driver (through your programming language) and insert into the database accordingly.

There also may exist some email servers that actually store the messages directly into a database. Then you can build queries that can move and archive the data into a table/schema of your choice.

Hope this helps,

Jeffrey Kevin Pry

Jeffrey Kevin Pry
  • 3,266
  • 3
  • 35
  • 67
  • 1
    PHP is very capable of handling this task. The `PEAR Mail_mimeDecode` library is easy to use. – Michael Berkowski Jun 29 '11 at 12:48
  • @Michael: I didn't say it wasn't (see third paragraph of my OP), I said it wasn't ideal. PHP is designed for web applications, this isn't a web application. Also, PHP is far slower than a compiled solution like C# or C++. See http://naspinski.net/post/AspNet-vs-php--speed-comparison.aspx (looking at ASP.net as C#) and find that in some cases PHP is 10 times slower than PHP. – Jeffrey Kevin Pry Jun 29 '11 at 13:24