0

I have the following code working in PHP 7, i use it to save my mail inbox into my db.

$hostname = '{imap.gmail.com:993/imap/ssl/novalidate-cert}'; 
$username = 'Myemail@gmail.com'; $password = 'Mypassword'; 
$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());
print_r(imap_errors());

$MC = imap_check($inbox);
$num = imap_num_msg($inbox);
if($num > 0) {
    //open MySQL connection
    $mysqli = new mysqli("localhost","root","password","mydb");
    //get from, date and subject
    $result = imap_fetch_overview($inbox,"1:{$MC->Nmsgs}",0);
    foreach ($result as $overview) {
        $message = imap_fetchbody($inbox, $overview->msgno, 1);
        echo "Next message:";
        echo "<br>";
        echo "#{$overview->msgno} - Date: ({$overview->date}) - From: {$overview->from} Subject: {$overview->subject}\n";
        echo "<br><br>";
        echo "Body: ".$message;
        $mysqli->query("INSERT INTO email VALUES ($overview->msgno, '$overview->date', '$overview->from', '$overview->subject',  '$message')");
    }
}

I want to know how i can make this in Codeigniter2, with PHP 5, using the controllers...

My intention is to save the inbox of my mail on a db, using IMAP. Then i want show it on a table in HTML, using one view in codeigniter.

Im newbie in codeigniter by the way, but i know how the system model-view-controller work.

Someone know how to do that?

Thanks you for your help, I appreciate it.

Sweetmoby
  • 27
  • 7
  • any reason to use CI 2.x ? – Vickel Sep 05 '20 at 11:03
  • Is a webpage already created in codeigniter 2, the guys just want to save the inbox of emails. I cant change the version of CI, im literally new in the company too. >. – Sweetmoby Sep 05 '20 at 14:09
  • If I remeber correctly CI 2.x used myql and not mysqli, have a look at the 2.x manual: https://codeigniter.com/userguide2/database/connecting.html – Vickel Sep 05 '20 at 14:32
  • Yes, it use mysql in PHP 5, and mysqli in PHP7. But how i can convert this single page in PHP, to the model view-controller used by CI2? That is what im trying to do now. Is a very short code, but i dont know how to make this possible in the controller and the view. – Sweetmoby Sep 05 '20 at 14:57

0 Answers0