To extract Subject and Mail from piped mail
Raw Email format:
Received: from gijs ([192.168.55.2]) by debian with smtp (Exim 3.12 #1 (Debian)) id 17AYXZ-0002BE-00 for ; Wed, 22 May 2002 18:00:41 +0200 From: "Gijs van Tulder" To: Subject: Test Date: Wed, 22 May 2002 18:00:41 +0200 Message-ID: <KNEOKJCOCHEDPIMPAIMIOEOJCJAA.gijs@debian> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.2416 (9.0.2910.0) Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 This is my message. Thank you.
The first part of the raw email contains the headers. A header contains information about the email. The header has a name, before the colon, and a value:
Header-Name: Value
. Important headers are the Subject header, containing the subject of the email, the From header, containing the origin of the email, and the To header, which tells us something about the recipient. The other headers are of minor importance.An empty line marks the end of the header part. After the first empty line, follows the body of the email.
<?php
$email = file_get_contents("php://stdin");
$subPos = strpos($email,"Subject");
$start = strpos($email,":",$subPos)+1;
$end = strpos($email,"\n",$start);
$subject = substr($email,$start, $end-$start);
$body = stristr($email, "\n\n");
//TEST IT
mail("yourMailId@example.com",$subject,$body);
?>
Read previous article on "how to pass email to a script file"
No comments:
Post a Comment