I'm facing problem with imap. Actually i m trying to fetch some mails whose subject words matches with keywords in my database. I m using an email id on which it works fine, but while using different email id's with same mails in it, it is showing maximum execution time of 30 sec exceeded. I also checked the imap settings in gmail, they are alright..
And also getting this error.. "Undefined property: stdClass::$subject"
<?php
// Create connection
$con=mysqli_connect("localhost",'root',"","project 6 sem");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
//else
//echo "Database connected..</br>";
?>
<?php
function Reply($prikey,$seckey,$submit3)
{
$con=mysqli_connect("localhost",'root',"","project 6 sem");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
echo $prikey;
echo $seckey;
$result = mysqli_query($con,"SELECT * FROM data1 where pkey='$prikey' and skey='$seckey'");
while($row = mysqli_fetch_array($result))
{
if($submit3 == "Positive")
{
$ans1 = $row['reply_yes'];
//echo $ans1;
}
else if($submit3 == "Negative")
{
$ans1 = $row['reply_no'];
//echo $ans1;
}
echo "<br>";
break;
//header('location:'.$_SERVER['HTTP_REFERER']);
}
mysqli_close($con);
return $ans1;
}
?>
<?php
$submit1 = NULL;
$submit2 = NULL;
if(isset($_POST['submit1']))
{
$submit1 = ($_POST['submit1']);
}
//echo $submit1;
if(isset($_POST['submit2']))
{
$submit2 = ($_POST['submit2']);
}
if(isset($_POST['select']))
{
$select = ($_POST['select']);
}
$cbody=0;
$subject=0;
$hostname= '{imap.gmail.com:993/ssl}INBOX';
$username = 'xxxxx';
$password = 'XXXXX';
/* try to connect */
$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Tiriyo: ' . imap_last_error());
/* grab emails */
$emails = imap_search($inbox,'ALL');
$count = imap_num_msg($inbox);
$temp=array();
$m=0;
$a=0;
$sk=array();
$pk=array();
$subcount=0 ;
$subarray=array() ;
$msgcount=0;
$msgarray=array() ;
$ans1 = "";
$b=0;
if($inbox)
{
$num = imap_num_msg($inbox);
rsort($emails);
$pk = array();
foreach ($emails as $email_number)
{
$b++;
echo "$b</br>";
// ini_set('max_execution_time',50);
$headers = imap_headerinfo($inbox, $email_number);
$sub_arr=explode(" ",$headers->subject);
$count_sub=count($sub_arr);
$pkey=array("Permission","permission",
"Application","application",
"Complaint","complaint",
"Enquiry","enquiry",
);
$skey=array("lab","Lab","auditorium","Auditorium","IT Parking","leave");
for($j=0;$j<$count_sub;$j++)
{
if($a==4)
break;
for($r=0;$r<count($pkey);$r++)
{
if($a==4)
break;
if($sub_arr[$j]==$pkey[$r])// Find the Primary key i.e from Subject
{
$a++;
$sub=$headers->subject;
$subarray[$subcount]=$headers->subject;
$subcount+=1;
//echo "<b>$headers->subject</b></br>";
$message=imap_fetchbody($inbox,$email_number,1);
$msgarray[$msgcount]=imap_fetchbody($inbox,$email_number,1);
$body=explode(" ",$msgarray[$msgcount]);
$msgcount+=1;
$count=count($body);