First of all check who u credit :p
Secondly why don't you just try to fix it yourself?
There was just a typo in the regexp:
- #^from\s*:\s*([^>]+)(<([^>]+)>)?#si
+ #^from\s*:\s*([^<]+)(<([^>]+)>)?#si
Hopefully this will help you even more:
<?php
/**
* @param string $runlevel
* @return mixed
*/
function fetchSender ( $mailText ) {
$mailText = explode( "\n" , $mailText ) ;
foreach ( $mailText AS $mailLine ) {
$mailLine = trim ( $mailLine ) ;
if ( strtoupper ( substr ( $mailLine , 0 , 4 ) ) == 'FROM' ) {
preg_match ( '#^\s*FROM\s*:\s*(([^<]+)(\<([^>]+)\>)?)#si' ,
$mailLine , $parts );
break ;
}
}
if ( is_array ( $parts ) === FALSE ) {
return FALSE ;
} else {
return array ( 'name' => isset ( $parts[2] ) ? $parts[2] : 'unknown' ,
'from' => isset ( $parts[1] ) ? $parts[1] : 'unknown' ,
'mail' => isset ( $parts[4] ) ? $parts[4] : 'unknown' ) ;
}
}
/**
* @param array $strings
* @return void
*/
function debug_FetchSender ( $strings ) {
echo '<pre>';
foreach ( $strings AS $string ) {
$sender = fetchSender ( $string );
$sender = array_map ( 'htmlspecialchars' , $sender ) ;
print_r ( $sender );
}
echo '</pre>';
}
debug_FetchSender ( array ( 'FROM: Red Wingate <[EMAIL PROTECTED]>' ,
'FROM: Red Wingate' ,
'FROM: [EMAIL PROTECTED]' ) ) ;
?>
[...]
>> Thanks Aiden for ur help
>>
>> i used ur code and i got
>>
>> name as Red Wingate<[EMAIL PROTECTED]
>> and no email.
>>
>> So pls correct the code and send me such that i get name and email
>> separately.
>>
>> Regards
>> syed
[...]
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php