The Cache: Technology Expert's Forum
 
*
Welcome, Guest. Please login or register. September 23, 2019, 06:49:18 AM

Login with username, password and session length


Pages: [1]
  Print  
Author Topic: [Request Code] A function to validate email links  (Read 3679 times)
basura
Rookie
**
Offline Offline

Posts: 13


View Profile
« on: November 23, 2007, 06:43:34 AM »

Hi there, as i suppose, there is not a PHP Class that could allow to a server read SMTP messages from an incoming account to verify the link that receives.

For example, if you sign up into a forum, inmediatly the script sends a link to verify that you are the right person with a link that you must click.

There is any script -cURL php Class- that allow making this automatically?

Please help me on finding something similar...

PS:

Im still waiting for the auto account email generator (Yahoo, Hotmail, GMail...) If anyone have it too.... Wink

Thanks in advance,aka SlimeLORD
Logged

No links in signatures please
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #1 on: November 26, 2007, 09:43:56 AM »

I'm confused SLord - are you saying you actually want to *receive* the messages that are sent to verify that you are a real person?

If that is the case, then you need POP3 or IMAP, not SMTP. I use a class called, cleverly, "imapMail" from an author named Harish Chauhan. I modified it just a bit to do some things that I wanted to do, but out of the box his class will do what you need. I chose IMAP rather than POP3 because the possibility of a server getting corrupted with large amounts of undelivereds is higher. (Jeepers, why would THAT ever happen?  Roll Eyes )

Here is a small snippet of code that would demonstrate using his class. It is available at PHP Classes, or a quick google of "php imap class harish" will do you.

Code:
<?php

$imap 
= new imapMail
$userName 'someuser';
$password 'apassword';
$host 'mail.perkiset.org';

if (!
$imap->open($aHost))
die("emailRetriever cannot connect to $host");

$imap->login($userName$password);
if (
$imap->error)
die("emailRetriever died connecting as $userName{$imap->error}");

$imap->open_mailbox('INBOX');
if (
$imap->error)
die("emailRetriever died opening INBOX as $userName{$imap->error}");

// OK - we're in.. get any messages, flag them for delete and close up...
$msgCount $imap->get_msglist();

while (
$msgCount 0)
{
$buffer mysql_escape_string($imap->get_message($msgCount));

// do something with $buffer - I write it to a DB for later handling

$imap->delete_message($msgCount);
$msgCount--;

}

$imap->close_mailbox();

?>

Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
JasonD
Expert
****
Offline Offline

Posts: 100


View Profile
« Reply #2 on: November 27, 2007, 02:10:49 AM »

Quote
If that is the case, then you need POP3 or IMAP, not SMTP

Without being a huge technical bore you can do it using the SMTP protocol but it would be extremely unusual for that to happen these days.

Many eons ago, when the (what was then) the largest UK ISP Demon was set up it decided to give everyone a host under it's main domain demon.co.uk - All email was transferred to you using SMTP and that could still be the case now
Logged
ratthing
Journeyman
***
Offline Offline

Posts: 75


View Profile
« Reply #3 on: November 27, 2007, 09:00:05 AM »

Rather than thinking of it in terms of the protocol, SMTP, think of it in terms of MUA or MTA.  Sendmail, postfix, and exim are all MTAs, mail transfer agents.  What you want to do is access and manipulate mail that's already been delivered, for this you need a MUA, or mail user agent.  The simplest tool I know of to deal with manipulating remote mail to get it to a local spool file is fetchmail (if you're on UNIX).  At that point the mail is in a file on your local machine.

You could use procmail, which includes a ton of filtering options, and could be used to trigger scripts, even.

I'm always mindful to remember the UNIX way...lots of small tools strung together to do more powerful things...why reinvent the wheel?
There's perl modules built do mail fetching and manipulation, I know.  I'd think there's likely a PHP class library.

=RT=
Logged
vsloathe
vim ftw!
Global Moderator
Lifer
*****
Offline Offline

Posts: 1669



View Profile
« Reply #4 on: November 27, 2007, 09:28:50 AM »

I can't be arsed to find it, but yeah there's a large PEAR/PECL module for it as well as several smaller more lightweight PHP libs. Parse out the links from the email with regex or whatever. Some places like myspace send their emails base64 encoded so you need to decode base64 at times but that's like a single line of code to call another prewritten lib (been done tons of times already as well).
Logged

hai
krustee
Rookie
**
Offline Offline

Posts: 33


View Profile
« Reply #5 on: May 15, 2009, 12:09:32 AM »

Had this problem a while ago when I was using gmail and had to verify my address. The class suggested here I could not get to work because gmail requires ssl. That's not to say it couldn't work but I didn't want to spend to long on it.

There is php_imap you can install to php and then use the function imap_open. I found this very easy to implement with gmail.

http://uk2.php.net/imap_open

Code:
<?php

$mbox 
imap_open("{imap.gmail.com:993/imap/ssl}INBOX",address@gmail.com","password")
or die("
can't connect: " . imap_last_error());

echo "<h1>Headers in INBOX</h1>\n";
$headers = imap_headers($mbox);

if ($headers == false) {
    echo "Call failed<br />\n";
} else {
    foreach ($headers as $val) {
        echo $val . "<br />\n";
    }
}

imap_close($mbox);
?>


edit* A good link here that explains the use thoroughly: http://docstore.mik.ua/orelly/webprog/pcook/ch17_04.htm
« Last Edit: May 15, 2009, 12:20:14 AM by krustee » Logged
Bompa
Administrator
Lifer
*****
Offline Offline

Posts: 564


Where does this show?


View Profile
« Reply #6 on: May 15, 2009, 12:32:49 AM »

wow thecache has been up for a year and a half?  where has the time gone?

anyways, i think the OP wants an auto-email-activator.

whatever

Bomps
Logged

"The most beautiful and profound emotion we can experience is the sensation of the mystical..." - Albert Einstein
perkiset
Olde World Hacker
Administrator
Lifer
*****
Offline Offline

Posts: 10096



View Profile
« Reply #7 on: May 15, 2009, 06:21:08 PM »

Actually had our 2 year anniversary on April 12th my friend.

No lie, time just flies. Thanks for your support here, as always.
Logged

It is now believed, that after having lived in one compound with 3 wives and never leaving the house for 5 years, Bin Laden called the U.S. Navy Seals himself.
Pages: [1]
  Print  
 
Jump to:  

Perkiset's Place Home   Best of The Cache   phpMyIDE: MySQL Stored Procedures, Functions & Triggers
Politics @ Perkiset's   Pinkhat's Perspective   
cache
mart
coder
programmers
ajax
php
javascript
Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks


Valid XHTML 1.0! Valid CSS!