...

View Full Version : Parameter into Variable



cosmoray
05-21-2011, 05:39 AM
I am trying to grab the "fromaddress" of every email that comes into a certain inbox. Is there an easy way to display this value without writing a line of code for each message number?



$from = imap_header($mbox, 1);
echo "$from->fromaddress <br />";

$from = imap_header($mbox, 2);
echo "$from->fromaddress <br />";


Additionally, how do I turn a specific "fromaddress" into a variable?

gvre
05-21-2011, 08:38 PM
Try this (change MAILSERVER.DOMAIN.COM, EMAIL, PASSWORD).


<?php
$mbox = imap_open("{MAILSERVER.DOMAIN.COM:143/imap/novalidate-cert}INBOX", "EMAIL", "PASSWORD");
$totalrows = imap_num_msg($mbox);
for ($i = 1; $i <= $totalrows; $i++)
{
$header = imap_header($mbox, $i);
$from = $header->fromaddress;
if (($pos = strpos($from, "<")) !== false)
{
$from = substr($from, $pos+1);
$from = substr($from, 0, -1);
}
echo $from . "\n";
}

cosmoray
05-21-2011, 09:41 PM
Works perfectly, thanks for the help.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum