I am forwarding my email coming to my domain to a php script. Its quite big, I don't know why stackoverflow is not allowing me to post full lenth as it gives error this looks like spam.
However, Its date part looks something like
.......\nFrom: Firstname Lastname <[email protected]>\nDate: Sun, 17 Feb 2019 08:09:37 +0545\nMessage-ID: <[email protected]>\nSubject:.......
My intention is to get the received datetime of this email.
There I can see Date: Sun, 17 Feb 2019 08:09:37 +0545
. This date is the required datetime for me. How, can I get it?
I tried exploding with preg_split('/\r\n|\r|\n/', $_POST['headers']);
but then I can't get Idea as it seems series of strings.
"Received: by mx0035p1mdw1.sendgrid.net with SMTP id ADiBRHCowl Sun, 17 Feb 2019 02:59:38 +0000 (UTC)",
"Received: from mail-ed1-f48.google.com (mail-ed1-f48.google.com [209.85.208.48]) by mx0035p1mdw1.sendgrid.net (Postfix) with ESMTPS id DB6E7A05D27 for <[email protected]>; Sun, 17 Feb 2019 02:59:37 +0000 (UTC)",
"Received: by mail-ed1-f48.google.com with SMTP id m35so7028682ede.10 for <[email protected]>; Sat, 16 Feb 2019 18:59:37 -0800 (PST)",
"DKIM-Signature: v=1; a=rsa-sha256; c=relaxed\/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=ttLV0Sk78+4DRG2CM0f\/kiWFXPnwCHm0Y\/1zM9lMrRo=; b=Dgyv4S\/TDdo61RsYchmhkFnFtG8VksVIeAimm7WOnHSv6chN+LOG25ufsh4\/51xX1Z pjQvuiXnuR7MawZ0B\/WZxB4F4309XT9SIrZMBX9\/5HHd\/SddFx1LZ6XVS2qEvaVV9B\/9 4v\/wqNhnNr7Vy1GlKbUq6buB9l4fk9J+ralDNF6lrDbP1XVCv+58Qp0UipMLPzYmFGnf EtylH7N4vVNoOjww15MwT5xrgW3ylfSJLZXog3TBxK+v8fGFKQ0UOH\/+C5PL0sQaFVM5 EVGtwQgqbBeEhJnG77xVuApcerYNYY+gM1Sixjb4NhRtsKgE5fOTAzA3N+jXbDIVunsZ F45g==",
"X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed\/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=ttLV0Sk78+4DRG2CM0f\/kiWFXPnwCHm0Y\/1zM9lMrRo=; b=s\/ovc9XPMypTBh6anKxw1WFQRJ3I4AGVFaQdu9L0buU2m8tl2JFPLWOYeliRS5K\/Jd WLiTXfRdFw8OpAWuKUbMt0wQ+gZXd0AwpJb\/t5KFs+Fh7l0cjWRSK\/0ZzADqagoyDmhC ISSRazoYBu2h9IeWdOhFV4i+VBvyhkXqauggB6kvZxG4GM\/ulB7sj5zYajnVBt5SfSI1 9SHMkkZrYerI6mCAKgqr\/eEj8E0IYgaKlhct9TlZbh9wsmYUQoDzp4Wf9JET5jhL7Lya 3Pa41NZepc03HfGOcnYadrPfrIz7O2Tm++22D0LBTzozkskwlJqqZz\/rLf0Osu81q80h VdEg==",
"X-Gm-Message-State: AHQUAuaQnQxerRWkc4sbGZmEt9JioFURi6LQDVYBzb60RKG+21LzjDlV OgAylSy0nmPPAEI7A\/Faxook200gMFui+BFD8sWrBg==",
"X-Google-Smtp-Source: AHgI3IZGrcH6ngLPOL8YS8PuOU6OPlSk2Q2DDeKmX41lGFBsvhtZ2FFtGkGypCSGCeVJd\/wP6i+pi2S6v5EIJaZOxNA=",
"X-Received: by 2002:aa7:dacd:: with SMTP id x13mr13739830eds.24.1550372376434; Sat, 16 Feb 2019 18:59:36 -0800 (PST)",
"MIME-Version: 1.0",
"From: Firstname Lastname <[email protected]>",
"Date: Sun, 17 Feb 2019 08:44:24 +0545",
"Message-ID: <CACX9xtmKSuZYgnXXEq-z=jtBwG4DG=ytptVVCOsY7SEOi2o_KQ@mail.gmail.com>",
"Subject: dummy12",
"To: [email protected]",
"Content-Type: multipart\/alternative; boundary=\"000000000000c45c6e05820e32b0\"",
""
How can I get datetim from this line "Date: Sun, 17 Feb 2019 08:44:24 +0545"
update:
After preg_split $res = preg_split('/\r\n|\r|\n/', $_POST['headers']);
if(count($res)>0){
$output = $res[10];
}
At this point $output is Date: Sun, 17 Feb 2019 08:09:37 +0545
I have found the solution, may not be it is best but it is doing the job.
$f_header = preg_split('/\r\n|\r|\n/', $_POST['headers']);
if(count($f_header)>0){
$output = substr("$f_header[10]",6);
$date = explode("+",$output);
$dt = date('Y-m-d h:i:s', strtotime($date[0]));
}