Allow full name to be passed to mailer

[MAILPOET-2307]
This commit is contained in:
Pavel Dohnal
2019-09-04 15:53:11 +02:00
committed by Jack Kitterhing
parent 0b96d13d1a
commit ef29a301fc
2 changed files with 9 additions and 2 deletions

View File

@@ -174,8 +174,9 @@ class Mailer {
if (isset($subscriber['address'])) $subscriber['email'] = $subscriber['address']; if (isset($subscriber['address'])) $subscriber['email'] = $subscriber['address'];
$first_name = (isset($subscriber['first_name'])) ? $subscriber['first_name'] : ''; $first_name = (isset($subscriber['first_name'])) ? $subscriber['first_name'] : '';
$last_name = (isset($subscriber['last_name'])) ? $subscriber['last_name'] : ''; $last_name = (isset($subscriber['last_name'])) ? $subscriber['last_name'] : '';
if (!$first_name && !$last_name) return $subscriber['email']; $full_name = (isset($subscriber['full_name'])) ? $subscriber['full_name'] : null;
$full_name = sprintf('%s %s', $first_name, $last_name); 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 = trim(preg_replace('!\s\s+!', ' ', $full_name));
$full_name = $this->encodeAddressNamePart($full_name); $full_name = $this->encodeAddressNamePart($full_name);
$subscriber = sprintf( $subscriber = sprintf(

View File

@@ -155,6 +155,12 @@ class MailerTest extends \MailPoetTest {
'email' => 'test@email.com', 'email' => 'test@email.com',
]) ])
)->equals('First Last <test@email.com>'); )->equals('First Last <test@email.com>');
expect($mailer->formatSubscriberNameAndEmailAddress(
[
'full_name' => 'First Last',
'email' => 'test@email.com',
])
)->equals('First Last <test@email.com>');
} }
function testItCanConvertNonASCIIEmailAddressString() { function testItCanConvertNonASCIIEmailAddressString() {