?
Solved

php imap

Posted on 2013-10-31
6
Medium Priority
?
284 Views
Last Modified: 2013-10-31
I having trouble inputting emails content  into a mysql database it only put one in.

<?php 
$imap = imap_open("{".$host.":143/novalidate-cert}INBOX", $user, $pass)or die(imap_last_error()); 
?><?php do{?><?php

   $counter++;
     
    $num = imap_num_msg($imap); 

	
	 
           
		  $partno = "1";

 $content_of_email= (imap_fetchbody($imap, $num, $partno));
          
		 
 $insertSQL = "INSERT INTO  `import`.`emails_in` (
`id` ,
`sContent` ,
`time`
)
VALUES (
NULL ,  '".$content_of_email."', 
CURRENT_TIMESTAMP
);";
                       

  mysql_select_db($database_con, $_con);
  $Result1 = mysql_query($insertSQL, $_con) or die(mysql_error());
     
	


    //move the email to our saved folder
    //$imapresult=imap_mail_move($imap,'1:'.$num,'INBOX.done');
    
    

	 

     
	 

 



} while ($num==0); 
  //close the stream 
     imap_close($imap);
	 echo $counter;
	 
	  ?>

Open in new window

0
Comment
Question by:beridius
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 39615639
What is the value of $num?  The way this is written it will only work once, unless $num is zero.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 39615642
And in semi-related news, you will need to get off MySQL, because PHP is doing away with the MySQL extension.  This article explains why and shows you what you must do to keep your scripts running.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/PHP_Databases/A_11177-PHP-MySQL-Deprecated-as-of-PHP-5-5-0.html
0
 
LVL 2

Author Comment

by:beridius
ID: 39615727
it goes round and round but only collects the first email and input that lots of times in the DB
0
WordPress Tutorial 3: Plugins, Themes, and Widgets

The three most common changes you will make to your website involve the look (themes), the functionality (plugins), and modular elements (widgets).

In this article we will briefly define each again, and give you directions on how to install them.

 
LVL 111

Expert Comment

by:Ray Paseur
ID: 39615739
Let me try this simple question again.
What is the value of $num?
0
 
LVL 2

Author Comment

by:beridius
ID: 39615750
$num is the number of  emails I have changed it to counter =0  
<?php 
$counter=0;
$imap = imap_open("{".$host.":143/novalidate-cert}INBOX", $user, $pass)or die(imap_last_error()); 
?><?php do{?><?php

   $counter++;
     
    $num = imap_num_msg($imap); 

	
	 
           
		  $partno = "1";

 $content_of_email= (imap_fetchbody($imap, $num, $partno));
          
		 
 $insertSQL = "INSERT INTO  `import`.`emails_in` (
`id` ,
`sContent` ,
`time`
)
VALUES (
NULL ,  '".$content_of_email."', 
CURRENT_TIMESTAMP
);";
                       

  mysql_select_db($database_con, $_con);
  $Result1 = mysql_query($insertSQL, $_con) or die(mysql_error());
     
	


    //move the email to our saved folder
    //$imapresult=imap_mail_move($imap,'1:'.$num,'INBOX.done');
    
    

	 

     
	 

 



} while ( $counter==0); 
  //close the stream 
     imap_close($imap);
	 echo;
	 
	  ?>

Open in new window


but still only get the first email
0
 
LVL 58

Accepted Solution

by:
Gary earned 2000 total points
ID: 39615758
Try this

<?php 
$imap = imap_open("{".$host.":143/novalidate-cert}INBOX", $user, $pass)or die(imap_last_error()); 
$msgcount = imap_num_msg($imap); 

for($num = 1; $num <= $msgcount; $num++) {

 $partno = "1";

 $content_of_email= (imap_fetchbody($imap, $num, $partno));
	 
 $insertSQL = "INSERT INTO  `import`.`emails_in` (`id` ,`sContent` ,`time`)VALUES (NULL ,  '".$content_of_email."', CURRENT_TIMESTAMP);";

  mysql_select_db($database_con, $_con);
  $Result1 = mysql_query($insertSQL, $_con) or die(mysql_error());
   
} 

imap_close($imap);
?>

Open in new window

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question