I am using this absolute amazing piece of code: https://github.com/plancake/official-library-php-email-parser/blob/master/PlancakeEmailParser.php
But the one thing it is missing is the ability to get the From email address.
I have simple added:
public function getFromEmail()
{
if (!isset($this->rawFields['from']))
{
return false;
}
return $this->rawFields['from'];
}
But how would I get only the email address part at the moment it returns: John Smith<john@gmail.com>
?
Also I would need this to work if the From address was only john@gmail.com
?
Thanks to the answers this was the finished code:
public function getFromEmail()
{
$email = trim($this->rawFields['from']);
if(substr($email, -1) == '>'){
$fromarr = explode("<",$email);
$mailarr1 = explode(">",$fromarr[1]);
$email = $mailarr1[0];
}
return $email;
}