sseeley Posted June 13, 2009 Share Posted June 13, 2009 I am trying to process an incoming email. I am using the code below. I want to use the $from to seach a database, however the $from is just providing a name, rather than the email address. Can anyone help me find the full email address? $fd = fopen("php://stdin", "r"); // Do whatever must be done $email = ""; while (!feof($fd)) { $email .= fread($fd, 1024); } 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; } } Many thanks Stuart Link to comment https://forums.phpfreaks.com/topic/162043-solved-incoming-email-address/ Share on other sites More sharing options...
MadTechie Posted June 13, 2009 Share Posted June 13, 2009 well the matches should be okay, could you echo out a full header and from line, and post it here Link to comment https://forums.phpfreaks.com/topic/162043-solved-incoming-email-address/#findComment-855032 Share on other sites More sharing options...
sseeley Posted June 13, 2009 Author Share Posted June 13, 2009 From [email protected] Sat Jun 13 12:10:00 2009 Received: from localhost ([127.0.0.1] helo=diamond.speednoc.com) by diamond.speednoc.com with smtp (Exim 4.69) (envelope-from ) id 1MFWjw-0001P4-PE for [email protected]; Sat, 13 Jun 2009 12:10:00 -0500 Received: from CAS01.apps4rent.com ([198.77.13.241] helo=CAS01.apps4rent.com) with IPv4:25 by diamond.speednoc.com; 13 Jun 2009 12:10:00 -0500 Received: from EXMBX01.apps4rent.net ([192.168.168.218]) by cas01.apps4rent.net ([192.168.168.241]) with mapi; Sat, 13 Jun 2009 10:09:57 -0700 From: Stuart Seeley To: "[email protected]" Date: Sat, 13 Jun 2009 10:09:56 -0700 Subject: Leave Thread-Topic: Leave Thread-Index: AQHJ7EnGQW5eznLCw0yh7rPvuTRnNQ== Message-ID: <[email protected]> Accept-Language: en-US Content-Language: en-GB X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: en-US Content-Type: multipart/alternative; boundary="_000_3B6DD99EBCA05E48A2042D7960A54C7A04DB13FFCEEXMBX01apps4r_" MIME-Version: 1.0 X-Assp-Delay: [email protected] not delayed (auto accepted); 13 Jun 2009 12:10:00 -0500 X-Assp-Score: 8 (No Spoofing Allowed '[email protected]') X-Assp-Received-SPF: softfail (cache) ip=198.77.13.241 [email protected] helo=CAS01.apps4rent.com X-Assp-Score: 3 (SPF softfail) X-Assp-Envelope-From: [email protected] Link to comment https://forums.phpfreaks.com/topic/162043-solved-incoming-email-address/#findComment-855036 Share on other sites More sharing options...
.josh Posted June 13, 2009 Share Posted June 13, 2009 if (preg_match("/^From ([^\s]*)/", $lines[$i], $matches)) Link to comment https://forums.phpfreaks.com/topic/162043-solved-incoming-email-address/#findComment-855040 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.