View Single Post
  #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
Reply With Quote