Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save rydurham/c59d065ec66924f957dd to your computer and use it in GitHub Desktop.
Save rydurham/c59d065ec66924f957dd to your computer and use it in GitHub Desktop.
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