Jump to content

Recommended Posts

I am trying to search an email header for the email address after it was piped to the script.

 

This is what the header and code look like:

 

Header

From me@mysite.com Sun Feb 14 17:45:41 2010

 

Code

if (preg_match("/^From (.*)/", $lines[$i], $matches)) {
$from = $matches[1];
}

 

Outputs "me@mysite.com Sun Feb 14 17:45:41 2010"

 

I want it to output just "me@mysite.com"

 

Any Ideas?

Link to comment
https://forums.phpfreaks.com/topic/192089-preg_match-help/
Share on other sites

What if the header looks like this and is in an $email variable:

 

Header

From me@mysite.com Mon Feb 15 11:34:42 2010 Received: from xx-xx-xx-xx.dhcp.eucl-nbb.wi.charter.com ([xx-xx-xx-xx] helo=[xx-xx-xx-xx]) by xx.xx.com with esmtpa (Exim 4.69) (envelope-from ) id 1Nh5mL-00035o-Ti for rsv

 

Code

if (preg_match("/^From (\S+)/", $email[$i], $matches)) {
$from = $matches[1];
}

 

It doesn't output anything. I want it to output "me@mysite.com".

Link to comment
https://forums.phpfreaks.com/topic/192089-preg_match-help/#findComment-1012739
Share on other sites

If your not sure where it's from, why is it there? Of course it doesn't output anything, hence the fact I had the big fat if at the start of my post. If $email contains the header then it should be...

 

if (preg_match("/^From (\S+)/", $email, $matches)) {
   $from = $matches[1];
}

Link to comment
https://forums.phpfreaks.com/topic/192089-preg_match-help/#findComment-1012752
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.