I have here a very challenging work that every boss tell the programmer to do
In this file i had retrieve the text from the mailbox and then i create the query once the query was created then we can easily run it.
I had test this code in my personal webmail
suraj@surajthapaliya.com.np(Use IMAP) and also i checked it on sthapaliya@wlink.com.np (POP3)
<?php
/*
Name: Mail Retrieve
when the user send the mail it should be the format like this
Message Part
----------------------------------------
Priority~High
Message~I Have a problem in Cable Network
------------------------------------------------
*/
$pop_host = "{mail.surajthapaliya.com.np/imap}INBOX";
/*
If you use pop then
Set the Pop server for eg. {pop.surajthapaliya.com.np:110/pop3}INBOX
*/
$mbox = imap_open ("$pop_host", "username", "password");
// Open the Mailbox by given host ,Username and Password
$messages = imap_search ($mbox, "TO sthapaliya");
/*
search on the mailbox currently opened in the given imap stream
TO "string" - match messages with "string" in the To:
*/
if ($messages)
{
$messagecount = count($messages); // Count The Messages
for ($i=0; $i<$messagecount; $i++)
{
$msgheader = imap_header($mbox, $messages[$i]); // returns an object of various header elements. according to mesage number
$to = $msgheader->to[0]; // Retrieve To
$from = $msgheader->from[0]; // Retrieve From
$von = $from->mailbox . "@" . $from->host;
$betreff = $msgheader->subject; // Retrieve Subject From Header
$cc = $msgheader->ccaddress; // Retrieve CC
$datum = $msgheader->date; // Date
echo "Subject : ".$betreff." <br> From: ".$von."<br>";
$body=imap_fetchbody($mbox,$messages[$i],"1"); // Fetch The Retrieve from body
//echo "<pre>".$body."</pre><br>";
// Make Query
$pos=strpos("$body","--"); // It search the position according to the -- string (it may be virus scaning text)
if($pos) {
$mainbody=substr($body,0,$pos);
} else {
$mainbody=$body;
}
// // Now Retrieve the data exclude the virus text
echo "Main".$mainbody."<br>";
$a=explode("\n",$mainbody); // seprate the main body text by Enter
$c=sizeof($a);
for($loop=0;$loop<$c;$loop++)
{
$innerE=explode("~",$a[$loop]); // Seprate the text by ~
$sE=sizeof($innerE);
for($j=0;$j<$sE;$j++)
{
if($j==1){
$data=$data."'".trim($innerE[$j])."',"; // Now retrieve the value text not a field
} else {
$field=$field."$innerE[$j]";
}
}
}