Indra
Indra

Reputation: 436

update mysql db when receive an email

i have some constraints about php.

can i update a record when i receive an email. for example: i have a table.

CREATE TABLE msg (
email varchar(100) NOT NULL default '',
msg varchar(255) NOT NULL default '',
)TYPE=MyISAM;

i have a no-reply email. like. [email protected] so when [email protected] receive an email from member. like: [email protected] and the body of the email like.

hii,. good morning world

so the script will run this query

$msg = '<the body of the email>'; //in this case 'hii,. good morning world'
$email = '<the email address of the sender>'; //in this case '[email protected]'
$query = "UPDATE msg SET msg = '$msg' WHERE email = '$email'";
$sql = mysql_query($query);

and my question is. how we know that [email protected] receive an email and run the script.?

Upvotes: 1

Views: 1306

Answers (1)

Carl Zulauf
Carl Zulauf

Reputation: 39558

There are a number of ways to do this. If [email protected] is a mailbox accessible via POP3 or IMAP you could have a script which logs in, checks for new messages, and triggers replies.

A simple solution would be to run this script every 10 minutes or so. If the script deletes messages after processing them, every time you see messages in the mailbox you know they are new. Otherwise your script will need to record the last message so it can only process newer messages on subsequent runs.

Check out PHP's mail extensions for some idea of how to talk to a POP3/IMAP mailbox. http://www.php.net/manual/en/book.imap.php

Upvotes: 2

Related Questions