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 Quote 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 Quote 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 me@stuartseeley.com 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 testemail@1083squadron.co.uk; 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: "testemail@1083squadron.co.uk" Date: Sat, 13 Jun 2009 10:09:56 -0700 Subject: Leave Thread-Topic: Leave Thread-Index: AQHJ7EnGQW5eznLCw0yh7rPvuTRnNQ== Message-ID: <3B6DD99EBCA05E48A2042D7960A54C7A04DB13FFCE@EXMBX01.apps4rent.net> 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: testemail@1083squadron.co.uk not delayed (auto accepted); 13 Jun 2009 12:10:00 -0500 X-Assp-Score: 8 (No Spoofing Allowed 'me@stuartseeley.com') X-Assp-Received-SPF: softfail (cache) ip=198.77.13.241 mailfrom=me@stuartseeley.com helo=CAS01.apps4rent.com X-Assp-Score: 3 (SPF softfail) X-Assp-Envelope-From: me@stuartseeley.com Quote 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)) Quote Link to comment https://forums.phpfreaks.com/topic/162043-solved-incoming-email-address/#findComment-855040 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.