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?
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
精彩评论