Last active
March 16, 2016 13:36
-
-
Save rydurham/c59d065ec66924f957dd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private function parseSenderEmail($body) | |
{ | |
$start = strpos($body, '<'); | |
// Make sure we have a valid starting point | |
if ($start === false) { | |
// This is not a properly formatted message | |
return ''; | |
} | |
// Add an offset to start after the '<' | |
$start += 1; | |
// Find the closing '>' | |
$end = strpos($body, '>'); | |
// Calculate the length of the email address | |
$length = $end - $start; | |
// Return the email address | |
return substr($body, $start, $length); | |
} | |
private function parseSenderName($body) | |
{ | |
$start = strpos($body, 'From:'); | |
// Make sure we have a valid starting point | |
if ($start === false) { | |
// This is not a properly formatted message | |
return ''; | |
} | |
// Add an offset to account for the 'From: ' text | |
$start += 6; | |
// The name should end before the first '<' | |
$end = strpos($body, ' <'); | |
// Calculate the length of the name | |
$length = $end - $start; | |
// Return the name | |
return substr($body, $start, $length); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment