How to get sender email address when reading emails

I’m reading email inbox but when I try to get the from header property. I don’t see the sender’s email address. I only see the name of the sender. How do I solve this?

Hello and welcome to our forums! :smiley:

Based on the example from the documentation, you can do the following:

/** @var Laminas\Mail\Header\From $from */
$from = $message->getHeader('from');
foreach ($from->getAddressList() as $address) {
    var_dump($address->getName(), $address->getEmail());
1 Like