Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7969151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:11:30+00:00 2026-06-04T07:11:30+00:00

I have to email headers and I want to extract the different data: from,

  • 0

I have to email headers and I want to extract the different data: from, subject, date, etc..

$mail1 = 'From: <encuestas@despegar.com>
To: 4fb661d55e409@ventas.ciudades.com
Subject: Califique nuestro servicio
Date: Sat, 19 May 2012 10:39:04 -0400
Message-ID: <3b6401cd35cd$23d08b90$0c01010a@despexds.net>
MIME-Version: 1.0';

$mail2 = 'Date: Fri, 21 Oct 2011 13:42:46 +0000 (GMT)
From: "Decolar.com" <non-reply@despegar.com>
To: 4ea15be894aca@ventas.ciudades.com
Message-ID: <2009175400.15674.1319204566275.JavaMail.root@uns02>
Subject: =?UTF-8?Q?Decolar.com_-_Solicita=C3=A7=C3=A3o_?=
 =?UTF-8?Q?de_compra_-_N=C3=BAmero:10603789?=
MIME-Version: 1.0';


preg_match("/Subject: (.)*(Date|Message-ID|From|To|MIME-Version):/s",$mail1,$m);        
print_r($m);       

I’m using the code above for getting just the subject, but the result is not the expected.

For mail1 I get:

Array
(
    [0] => Subject: Califique nuestro servicio
Date: Sat, 19 May 2012 10:39:04 -0400
Message-ID: <3b6401cd35cd$23d08b90$0c01010a@despexds.net>
MIME-Version:
    [1] => 

    [2] => MIME-Version
)

For mail2 I get:

Array
(
    [0] => Subject: =?UTF-8?Q?Decolar.com_-_Solicita=C3=A7=C3=A3o_?=
 =?UTF-8?Q?de_compra_-_N=C3=BAmero:10603789?=
MIME-Version:
    [1] => 

    [2] => MIME-Version
)

I both cases, subject is empty.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T07:11:31+00:00Added an answer on June 4, 2026 at 7:11 am

    I would probably do something like:

    function normalize_array($arr) {
        for ($res = array(), $i = 0; $i < count($arr); $i+=2) {
            $key = strtr($arr[$i],array(': '=>'','-'=>'_'));
            $res[$key] = $arr[$i+1];
        }
        return $res;
    }
    
    $mailData = normalize_array(preg_split('~([\w-]+: )~',$mail1,-1,PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY));
    print_r($mailData);
    

    which will return:

    Array
    (
        [From] => <encuestas@despegar.com>
    
        [To] => 4fb661d55e409@ventas.ciudades.com
    
        [Subject] => Califique nuestro servicio
    
        [Date] => Sat, 19 May 2012 10:39:04 -0400
    
        [Message_ID] => <3b6401cd35cd$23d08b90$0c01010a@despexds.net>
    
        [MIME_Version] => 1.0
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have email addresses like user1@gmail.com , user2@ymail.com user3@hotmail.com ... etc. I want a
I have these lines of code: $from = email@domian.com; $headers = From: . $from;
From a different account, I sent myself an email with the subject Test de
I have an email from a developer in which he says: As you may
I have 50 newsletters which all have different email accouts, hex colour codes and
i have the following code $subject = Subject Here; $headers = 'MIME-Version: 1.0' .
i want to show my email headers in a UITableView when inbox button clicked,
I have a directory full of email files, which look like this: From: Scoop
I have a script that is called from a email pipe. So someone emails
Hello from an SQL nO0b, I have three Select statements I want to join:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.