Re: Regular expression
| From: | Red Wingate | Date: | Wed, 30 Jun 2004 10:57:44 +0000 |
| Subject: | Re: Regular expression | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-189284@lists.php.net to get a copy of this message | ||
If you still like to gather the information without using any tools:
$email = explode( "\n" , $mailText );
foreach ( $email AS $emailLine ) {
$emailLine = trim( $emailLine );
if ( strtoupper ( substr( $emailLine , 0 , 4 ) ) == 'FROM' ) {
preg_match( '#^from\s*:\s*([^>]+)(<([^>]+)>)?#si' ,$emailLine ,$parts );
break ;
}
}
$name = $parts[1] ;
$email = $parts[3] ;
But you should consider the following:
FROM: Red Wingate <redeye@erisx.de>
FROM: Red Wingate
FROM: redeye@erisx.de
.....
Which makes working like this a pita.
-- red
> I suggest not using a regex.
>
> There are better tools for parsing an email, for example "formail".
>
> $email =
formail -x Return-Path;
>
> See google.com for more information
>
> Regards,
> Aidan
>
>
> "Syed Ghouse" <syed@jinis.com> wrote in message
> news:00d701c45e83$9a662a50$495aa8c0@jinis.com...
> Hi All
>
> will anyone give me a solution to get the name and email address of sender
> from the mail text below using regular expression.
>
> The result shud get
> name as syed ghouse
> and
> email as syed@jinis.com
>
> --- Mail text start ---
>
> Return-Path: <avijayanand@sdmimd.com>
> Delivered-To: syed@sdmimd.com
> Received: (qmail 25523 invoked by uid 508); 19 Jun 2004 06:23:25 -0000
> Received: from localhost (HELO 192.168.90.8) (127.0.0.1)
> by mail.jinis.com with SMTP; 19 Jun 2004 06:23:25 -0000
> Received: from 192.168.90.20 (proxying for 192.168.90.85)
> (SquirrelMail authenticated user vijayanand@sdmimd.com)
> by 192.168.90.8 with HTTP;
> Sat, 19 Jun 2004 11:53:25 +0530 (IST)
> Message-ID: <4875.192.168.90.20.1087626205.squirrel@192.168.90.8>
> Date: Sat, 19 Jun 2004 11:53:25 +0530 (IST)
> Subject: test
>
> From : 'syed ghouse' <syed@jinis.com>
>
> To: vijayanand@sdmimd.com
> Cc: syed@sdmimd.com,sss@sdmimd.com
> User-Agent: SquirrelMail/1.4.2
> MIME-Version: 1.0
> Content-Type: text/plain;charset=iso-8859-1
> Content-Transfer-Encoding: 8bit
> X-Priority: 3
> Importance: Normal
>
> test mail ignore
>
> --- Mail text end ---
>
>
> Regards
>
> Syed