Hey guys, somewhat new to PHP here, trying to get this project rolling. I have this script that checks an email address and returns the newest email in a table, works great. The problem is when I want to check multiple emails. I tried to put the script in a for loop and all it does it check the first email. It throws no errors, just doesn’t work. Think anyone could help me out? Also, take into account I’m brand new, so my code is very messy. Thanks!
[php]<?php
include (‘ID.php’);
include (‘secVar.php’);
for ($i=0; $i <= 1; $i++)
{
$inbox = imap_open($hn[$i],$un[$i],$pw[$i]) or die('Cannot connect to database: ’ . imap_last_error());
$emails = imap_search($inbox,‘ALL’);
if($emails) {
rsort($emails);
foreach($emails as $email_number) {
$overview = imap_fetch_overview($inbox,$email_number,0);
$message = imap_fetchbody($inbox,$email_number,2);
$body[] = imap_fetchbody($inbox,$email_number,2);
$date[] = ($overview[0]->date);
$from[] = ($overview[0]->from);
$subject[] = ($overview[0]->subject);
$body[0];
}
$ID=assignID($from[0], $ID);
$con = mysql_connect(“localhost”,“table”,“pw”);
if (!$con)
{
die('Could not connect: ’ . mysql_error());
}
mysql_select_db(“db”, $con);
$sql=“INSERT INTO deals (ID, dat, from
, subject, body)
VALUES
(’$ID’, ‘$date[0]’,’$from[0]’,’$subject[0]’,’$body[0]’) ON DUPLICATE KEY UPDATE subject = ‘$subject[0]’”;
if (!mysql_query($sql,$con))
{
die('Error: ’ . mysql_error());
}
}
}
[/php]