Jump to content

adding data to MySQL table by email


saint959

Recommended Posts

Hi,

 

I am hoping someone can help.

I need to allow users to send details through email into a MySQL database. Please if anyone could point me in the right direction it would be hugely helpful:

 

This is the code i have done so far:

 

<?php

$mbox = imap_open("{serverip:serverhost}", "email address", "email password");

 

$MC = imap_check($mbox);

$overview = imap_fetch_overview($mbox, "1:{$MC->Nmsgs}");

 

 

$msgcount = 1;

 

if (is_array($overview)) {

  foreach ($overview as $val) {

    $message_body = imap_fetchbody ( $mbox,$msgcount,'1');

    $messages_found[$msgcount] = "$val->from||$val->from||$val->to||toname||$val->subject||$message_body";

 

  $msgcount ++;

 

  }

}

$msgcount = 1;

include '../db.php';

 

$messagedate = date("Y-m-d");

 

foreach ($messages_found as $message_part){

$message_split = explode("||", $message_part);

 

$query = "INSERT INTO `$tablename` (`messagedate`,`fromnumber`,`fromname`,`tonumber`,`toname`,`subject`,`message`,`status`)

  VALUES ('$messagedate',";

 

foreach ($message_split as $message){

$message = str_replace('@findza.co.za','',$message);

$message = str_replace('http://','',$message);

$message = str_replace('<','',$message);

$message = str_replace('>','',$message);

 

$query .= "'$message',";

}

$query .= "'unread')";

 

print "</br></br>";

print "$query"; //printing the query to check the output before integrating with database

 

}

 

imap_close($mbox);

?> 

 

The above code does work, most of the time, but is there a way i can get the script to permantely monitor the catch all email account and run each time a new email gets found.

 

If someone has a better solution then please let me know

Link to comment
https://forums.phpfreaks.com/topic/47248-adding-data-to-mysql-table-by-email/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.