Alright,

first of all, in E-Mail Headers every param needs to be written in a 
seperate line, therefore following will work even with multiple recipients:

$recipients = array();
$header = explode( "\n" , $header );
foreach ( $header AS $param ) {
    $param = trim ( $param );

    if ( strtolower( substr( $param , 0 , 3 ) ) == 'to:' ) {
        $recipients[] = trim ( substr( $param , 3 ) );
    }
}

This will match every of these:

'TO:[EMAIL PROTECTED]'
'  TO: [EMAIL PROTECTED]'
' TO:Mr Baz <[EMAIL PROTECTED]>'
' TO:[EMAIL PROTECTED],[EMAIL PROTECTED],[EMAIL PROTECTED]'

etc. pp

  -- red

PS: I'm not sure about wether 'TO :' is allowed or not - sad thing :-)

Am Mittwoch, 7. April 2004 11:28 schrieb Simon Hayward:
> preg_match("/To: ([^<]+)<?([^>]+)?>?/i",$string,$matches);
>
> returns email in $matches[1] in the first instance
> and name in $matches[1] and email in $matches[2] in the second.
>
> -----Original Message-----
> From: Robert Kornfeld [mailto:[EMAIL PROTECTED]
> Sent: 07 April 2004 09:32
> To: [EMAIL PROTECTED]
> Subject: [PHP] regular expression
>
>
> hey, professionals out there:
>
> i need to write a parser for an email-header to retrieve the email of the
> 'To:'-field.
> there are 2 possibilities:
> 'To: [EMAIL PROTECTED]' or
> 'To: first foo <[EMAIL PROTECTED]>'
>
> i would only need the email-adress!
> does anyone know the regular expression that can handle both possibilities?
> (i give up!)
>
> thanx!
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
> Legal Disclaimer:-
>
> Internet communications are not secure and therefore the
> Barclays Group does not accept legal responsibility for the
> contents of this message.  Although the Barclays Group
> operates anti-virus programmes, it does not accept
> responsibility for any damage whatsoever that is caused
> by viruses being passed.  Any views or opinions presented
> are solely those of the author and do not necessarily
> represent those of the Barclays Group.
>
> Replies to this e-mail may be monitored by the Barclays
> Group for operational or business reasons.
>
> Barclays Bank PLC trading as "Shopsmart from Barclaycard".
> Registered Office: 54 Lombard Street
> London EC3P 3AH
> Registered in England, Registration No. 1026167.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to