Hobbyist_PHPer Posted March 5, 2011 Share Posted March 5, 2011 Hello Everyone... I'm having an issue with my looping and parsing of email via imap... Here is my code: <? require "connection.inc"; $mailbox = imap_open("{serverinformation}INBOX", "[email protected]", "thepassword"); if ($mailbox == false) { echo "<p>Error: Can't open mailbox!</p>"; echo imap_last_error(); } else { $num = imap_num_msg($mailbox); for ($i=0; $i < $num; $i++) { $content = imap_body($mailbox, $num); $siteid = stripos($content,"MOU"); $gwon = stripos($content, "MOSLXX-"); $TempSiteID = substr($content, $siteid, 7); $TempGraniteWorksOrderNumber = substr($content, $gwon, 13); echo '<p>Message #: '.$i.' - Site ID: '.$TempSiteID.' - Granite Works Order #: '.$TempGraniteWorksOrderNumber.'</p>'; } } imap_close($mailbox); ?> The result I get is unexpected... The output gives me each mail message number as expected, however, the information that I parsed for is always that of the last email message... Here's an example of the output: Message #: 0 - Site ID: MOU3963 - Granite Works Order #: MOSLXX-247119 Message #: 1 - Site ID: MOU3963 - Granite Works Order #: MOSLXX-247119 Message #: 2 - Site ID: MOU3963 - Granite Works Order #: MOSLXX-247119 Message #: 3 - Site ID: MOU3963 - Granite Works Order #: MOSLXX-247119 Message #: 4 - Site ID: MOU3963 - Granite Works Order #: MOSLXX-247119 Message #: 5 - Site ID: MOU3963 - Granite Works Order #: MOSLXX-247119 Message #: 6 - Site ID: MOU3963 - Granite Works Order #: MOSLXX-247119 Anybody tell me what I'm doing wrong here? Link to comment https://forums.phpfreaks.com/topic/229709-imap-looping-and-parsing/ Share on other sites More sharing options...
Hobbyist_PHPer Posted March 5, 2011 Author Share Posted March 5, 2011 Ah, I figured it out... just needed to step back from it for a moment... for ($i=1; $i < $num; $i++) { $content = imap_body($mailbox, $i); Link to comment https://forums.phpfreaks.com/topic/229709-imap-looping-and-parsing/#findComment-1183351 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.