Current location: Hot Scripts Forums » Programming Languages » PHP » How can I get the email address from a email?

How can I get the email address from a email?

Reply
  #1 (permalink)  
Old 12-01-07, 07:31 PM
Idealws Idealws is offline
New Member
 
Join Date: Oct 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
How can I get the email address from a email?

Hello,

I have a issue and have searched everywhere and cannot seem to come up with a
solution. I am assuming there is a regex I could use to fix this problem however
I am not very good with regex.

What I am trying to do is add to the scripot below to get the email address
from the person who sent the email. I got this script from the web and all
works great other than the fact I cannot get the actual email address from
the from field. It only give the 'Name' of the person.

I am also trying to figurew out a way to parse the email if it is in HTML and not
plain text.

PHP Code:
// read from stdin
$fd fopen("php://stdin""r");
$email "";
while (!
feof($fd)) {
    
$email .= fread($fd1024);
}
fclose($fd);

// handle email
$lines explode("\n"$email);

// empty vars
$from "";
$subject "";
$headers "";
$message "";
$splittingheaders true;

for (
$i 0$i count($lines); $i++) {
    if (
$splittingheaders) {
        
// this is a header
        
$headers .= $lines[$i] . "\n";

        
// look out for special headers
        
if (preg_match("/^Subject: (.*)/"$lines[$i], $matches)) {
            
$subject $matches[1];
        }
        if (
preg_match("/^From: (.*)/"$lines[$i], $matches)) {
            
$from $matches[1];
        }

    } else {
        
// not a header, but message
        
$message .= $lines[$i] . "\n";
    }

    if (
trim($lines[$i]) == "") {
        
// empty line, header section has ended
        
$splittingheaders false;
    }

If anyone could help me it would be greatly appreciated it.

Thanks in advance.

Regards,
Ray
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 12-04-07, 06:23 PM
robertark's Avatar
robertark robertark is offline
Newbie Coder
 
Join Date: Dec 2007
Location: Springfield, MO
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
You could also look in the reply-to header. Regex, you're pretty much on the right track, just print_r($lines) see if anything exists.
__________________
Knowledge Is Power And Without Power, You're Nobody. -Self
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Share on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
maintaining the same email address in a form cedric813 Perl 1 11-27-07 01:22 AM
can you use php to get someone's email address from a mailer? pagetta PHP 8 11-11-05 06:36 AM


All times are GMT -5. The time now is 11:44 PM.
vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.