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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.