Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Accessing email inbox

Status
Not open for further replies.

pdbowling

Programmer
Mar 28, 2003
267
US
Good day, All.

I searched for 'loop inbox' and only found topics discussing Sending mass mails. I have something different in mind but have no idea where to start. I'm a developer but have no experience in PHP.

I wanted to see if there was a way to access an email account associated with my website, loop through the received messages and do some processing on them.

I'll be getting many many messages to confirm a sign up by clicking a link in the email. What I'd like to do is automate this and have a script do it. There could be thousands since 'Blastomatic' will generate this many inquiries.

I'd like to open an email, scan for 'confirm' or 'verif' in the header or text and click the links in the email if 'confirm' or 'verif' is found.

I'm new to all of this web master stuff so if there is a nice freeware out there that does this, please suggest it, but I have no qualms with writing a script to do it if I could get a link to a tutorial on what function calls I need for accessing inboxes (if they exist).

Suggestions welcome. I do not however want to buy a service. I'm working on the cheap.

Thanks everyone.
Patrick

Gather or post content for free.
 
it's pretty much as simple as this

Code:
<?php

function parseMail(){
	$server = '{imap.server.net:443}';
	$mailbox = 'INBOX';
	$username = '';
	$password = '';
	
	//connect to mailbox
	$mbox = imap_open($server.$mailbox, $username, $password);
	if ($mbox === false) {
		die ('could not connect to mailbox');
	}
	
	//get mailbox information
	$mc = imap_check($mbox);
	
	//get message overviews
	$result = imap_fetch_overview($mbox,"1:$mc->Nmsgs}", 0);
	
	//now iterate through the messages
	foreach($result as $detail){
		if (!$detail->seen){	//if mail is 'unread' then parse
			//get body
			$body = imap_fetchbody($mbox, $detail->msgno, 1);
			parseBody($body);
		}
	}
	//close the connection
	imap_close($mbox);
}

function parseBody($body){
	//use preg_match
	$searchPattern = '/(confirm|verif)/i';
	preg_match($searchPatter, $body, $matches);
	if (isset($matches[1])){
		switch (strtolower($matches[1])){
			case 'confirm':
				//do something here
				break;
			case 'verif':
				//do something here
				break;
			default:
				//do nothing
		}
	}
}
?>

you would need to extract some more information from each mail body in order to identify the users id. you do this in the same way - using regular expressions.

then you don't so much 'click a link' as call the script that confirms/verifies the user.

there are list management/mailer daemons out there that typically user perl and do all of these things automatically. additionally there are some mta's like postfix which have some or all of these functions. but as you can see, the script is pretty straightforward to do yourself. just set up a cron job to run it regularly.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top