Hi,
Could someone look/try my code below. It grabs emails
from a mailbox and grabs emails within the BODY of the
email and sends the details to a database to match and
flag an account.
It works fine on 1 email, but if you get multiple
emails in the inbox in will revert to grabbing ONLY
the domain of the mailserver, and do not know why.
To try the code simply.
- Create a PHP file on your webserver, (e.g. pop.php)
- Copy the code below into it
- Change the database usr, pwd and db settings
- user, pass and mailserver settings
- Savie it. :)
Than....
- Make sure the mailbox you are setting up in the
script is an EMPTY mailbox. Please be aware if you
run the script on a full mailbox the script deletes
the emails in the inbox after it is ran so be careful.
- I suggest you create a new mailbox and use that.
- Send an email to the mailbox like this:
To: [EMAIL PROTECTED]
Subject: anything
Body: [EMAIL PROTECTED]
- Feel free to add other text, make sure an email
address is in the Body
- Now run the script on the one email in the inbox, it
will grab and echo the result
- Now send two emails with 2 different email addresses
in the Body
- Runt eh script, it should fail badly and not even
echo the correct address
Why is this?
It's not just the matter of echoing correctly I need
it to to be put into a mysql query correctly also to
flag accounts. On 1 email it works fine, one more
than 1 it fails mysql.
Could someone take a look and see what I have done
wrong please?
Thanks, Jerry
<?
$usr = "usr";
$pwd = "pass";
$db = "mydb";
$host = "localhost";
$cid = mysql_connect($host,$usr,$pwd);
mysql_select_db($db);
global $IP_RegExp_Match, $Host_RegExp_Match,
$Email_RegExp_Match;
$IP_RegExp_Match =
'\\[?[0-9]{1,3}(\\.[0-9]{1,3}){3}\\]?';
$Host_RegExp_Match = '(' . $IP_RegExp_Match .
'|[0-9a-z]([-.]?[0-9a-z])*\\.[a-z][a-z]+)';
$Email_RegExp_Match = '[0-9a-z]([-_.+]?[0-9a-z])*(%' .
$Host_RegExp_Match .
')?@' . $Host_RegExp_Match;
$user = 'emailuser';
$pass = 'emailpass';
$MAILSERVER =
"{mail.mymailserver.com:110/pop3/notls}"; //Para POP3
$mbox = @imap_open ($MAILSERVER,$user,$pass) or die
("Sorry can't connect - please check your settings");
$check = imap_mailboxmsginfo($mbox);
echo "Messages before delete: " . $check->Nmsgs . "<br
/>\n";
$headers = imap_headers($mbox);
if ($headers == false) {
echo "There are no messages to be deleted.<br
/>\n";
} else {
while (list ($key, $val) = each ($headers)) {
for ($i = 1; $i <= imap_num_msg($mbox); $i++)
{
$header = imap_headerinfo($mbox, $i, 80, 80);
$messageBody = imap_body($mbox, $i);
$messageBody = strip_tags($messageBody,
'<a><b><i><u>');
$messageBody = str_replace("\'", "", $messageBody);
$messageBody = str_replace("\\", "", $messageBody);
$messageBody = str_replace("\"", "", $messageBody);
$messageBody = str_replace("3D", "", $messageBody);
global $color, $Email_RegExp_Match;
$sbody = $messageBody;
$addresses = array();
/* Find all the email addresses in the body */
while(eregi($Email_RegExp_Match, $sbody, $regs)) {
$addresses[$regs[0]] = $regs[0];
$start = strpos($sbody, $regs[0]) +
strlen($regs[0]);
$sbody = substr($sbody, $start);
}
/* Replace each email address with a compose URL
*/
foreach ($addresses as $email) {
$body = str_replace($email, $comp_uri, $body);
mysql_query ("update users SET emailerror='y' WHERE
email='$email'") or die ("No");
};
imap_delete($mbox, 1);
$check = imap_mailboxmsginfo($mbox);
imap_expunge($mbox);
$check = imap_mailboxmsginfo($mbox);
};
}};
$check = imap_mailboxmsginfo($mbox);
echo "Messages after delete: " . $check->Nmsgs . "<br
/>\n";
if ($email) {
echo "Email: " . $email . "<br>\n";
}
imap_close($mbox);
?>
http://personals.yahoo.com.au - Yahoo! Personals
New people, new possibilities. FREE for a limited time.
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php