diff --git a/lib/Mailer/Mailer.php b/lib/Mailer/Mailer.php index 699f8cbd2b..10cf67adfb 100644 --- a/lib/Mailer/Mailer.php +++ b/lib/Mailer/Mailer.php @@ -174,8 +174,9 @@ class Mailer { if (isset($subscriber['address'])) $subscriber['email'] = $subscriber['address']; $first_name = (isset($subscriber['first_name'])) ? $subscriber['first_name'] : ''; $last_name = (isset($subscriber['last_name'])) ? $subscriber['last_name'] : ''; - if (!$first_name && !$last_name) return $subscriber['email']; - $full_name = sprintf('%s %s', $first_name, $last_name); + $full_name = (isset($subscriber['full_name'])) ? $subscriber['full_name'] : null; + if (!$first_name && !$last_name && !$full_name) return $subscriber['email']; + $full_name = is_null($full_name) ? sprintf('%s %s', $first_name, $last_name) : $full_name; $full_name = trim(preg_replace('!\s\s+!', ' ', $full_name)); $full_name = $this->encodeAddressNamePart($full_name); $subscriber = sprintf( diff --git a/tests/integration/Mailer/MailerTest.php b/tests/integration/Mailer/MailerTest.php index 6c6ca6e2af..4cb7ff102d 100644 --- a/tests/integration/Mailer/MailerTest.php +++ b/tests/integration/Mailer/MailerTest.php @@ -155,6 +155,12 @@ class MailerTest extends \MailPoetTest { 'email' => 'test@email.com', ]) )->equals('First Last '); + expect($mailer->formatSubscriberNameAndEmailAddress( + [ + 'full_name' => 'First Last', + 'email' => 'test@email.com', + ]) + )->equals('First Last '); } function testItCanConvertNonASCIIEmailAddressString() {