Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#26 Does not initialize the name property if not provided #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions SwiftMailer/MessageFormat/MessagePayloadV31.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,19 @@ private static function getMailjetHeaders() {
* @return array|null
*/
private function getReplyTo(Swift_Mime_Message $message) {
if (is_array($message->getReplyTo())) {
return array('Email' => key($message->getReplyTo()), 'Name' => current($message->getReplyTo()));
} elseif (is_string($message->getReplyTo())) {
return array('Email' => $message->getReplyTo());
$replyTo = $message->getReplyTo();

if (is_array($replyTo)) {
$email = key($replyTo);
$name = current($replyTo);

if (empty($name)){
return array('Email' => $email);
}

return array('Email' => $email, 'Name' => $name);
} elseif (is_string($replyTo)) {
return array('Email' => $replyTo);
} else {
return null;
}
Expand Down
26 changes: 26 additions & 0 deletions Tests/SwiftMailer/MailjetTransportv31Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,32 @@ public function testBulkSendMessages() {
}
}

public function testReplyToWithoutName(){
$message = new \Swift_Message('Test Subject', '<p>Foo bar</p>', 'text/html');
$message->setReplyTo('alice+replyTo@nowhere.com');
$message->setFrom('alice+from@nowhere.com');
$message->setTo('bob@nowhere.com');
$message->setBody("Hello world!", 'text/plain');

$transport = $this->createTransport();
$mailjetMessage = $transport->messageFormat->getMailjetMessage($message)['Messages'][0];

$this->assertEquals(["Email" => 'alice+replyTo@nowhere.com'], $mailjetMessage['ReplyTo']);
}

public function testReplyTo(){
$message = new \Swift_Message('Test Subject', '<p>Foo bar</p>', 'text/html');
$message->setReplyTo('alice+replyTo@nowhere.com', 'Alice');
$message->setFrom('alice+from@nowhere.com');
$message->setTo('bob@nowhere.com');
$message->setBody("Hello world!", 'text/plain');

$transport = $this->createTransport();
$mailjetMessage = $transport->messageFormat->getMailjetMessage($message)['Messages'][0];

$this->assertEquals(["Email" => 'alice+replyTo@nowhere.com', "Name" => "Alice"], $mailjetMessage['ReplyTo']);
}

/**
* @param string $email
* @param string $name
Expand Down