Featch mails from mails server using PHP script

by kalai 2010-06-20 17:06:58

Code to fetch mails from mail server and parse the mail content using delimiter

function br2nl($string){
$return=eregi_replace(' '[[:space:]]*>',chr(13).chr(10),$string);
return $return;
}
require("pop3.php");

/* Uncomment when using SASL authentication mechanisms */

$pop3=new pop3_class;
$pop3->hostname="your hostname"; /* POP 3 server host name */
$pop3->port=110; /* POP 3 server host port,
usually 110 but some servers use other ports Gmail uses 995 */
$pop3->tls=0; /* Establish secure connections using TLS */
$user="usrname"; /* Authentication user name */
$password="pwd"; /* Authentication password */
$pop3->realm=""; /* Authentication realm or domain */
$pop3->workstation=""; /* Workstation for NTLM authentication */
$apop=0; /* Use APOP authentication */
$pop3->authentication_mechanism="USER"; /* SASL authentication mechanism */
$pop3->debug=1; /* Output debug information */
$pop3->html_debug=1; /* Debug information is in HTML */
$pop3->join_continuation_header_lines=1; /* Concatenate headers split in multiple lines */

if(($error=$pop3->Open())=="")
{
if(($error=$pop3->Login($user,$password,$apop))=="")
{
if(($error=$pop3->Statistics($messages,$size))=="")
{

$result=$pop3->ListMessages("",0);
print" result ---";
print_r($result);
if(GetType($result)=="array")
{
for($messages=1;$messages<=count($result);$messages++)
{
$pop3->RetrieveMessage($messages,$headers,$body,-1);
$conn="";
for($line=0;$line {
$conn.= $body[$line]."
";
}

//$con=explode("======****======",$conn);

for($i=0;$i
$pos = strpos($con[$i], "##**^^");
if($pos)
{

$con[$i]=substr($con[$i],$pos+6);
$offset = 1;
//echo"$con ------";
$pos2 = strpos($con[$i], "##**^^");
echo "pos2 ------ $pos2";
$con[$i]=substr($con[$i],0,$pos2-4);
print"****=======****";
print "Sms ====== $con[$i]";
}

$con[$i]= htmlentities($con[$i], ENT_QUOTES);
$qq="select * from mytable where content like '$con[$i]' and uname like 'usr'";
$qqq= mysql_query($qq);
if(mysql_num_rows($qqq) >0){}else{
$ress = mysql_query("insert into sms values ('','usr','','','',NOW(),'none','$con[$i]','',0,0)");

}
#$pop3->DeleteMessage($messages);
}

}
}
}

}
}

Tagged in:

897
like
0
dislike
0
mail
flag

You must LOGIN to add comments