Skip to content

Commit

Permalink
Merge pull request #410 from caseyw/add-name-to-replyto-issue-390
Browse files Browse the repository at this point in the history
Adding name for ReplyTo for issue #390
  • Loading branch information
thinkingserious committed Jun 30, 2017
2 parents 32af89b + 5d56dbd commit 0e9fde3
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
2 changes: 1 addition & 1 deletion examples/helpers/mail/example.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ function kitchenSink()
$tracking_settings->setGanalytics($ganalytics);
$mail->setTrackingSettings($tracking_settings);

$reply_to = new ReplyTo("[email protected]");
$reply_to = new ReplyTo("[email protected]", "Optional Name");
$mail->setReplyTo($reply_to);

//echo json_encode($mail, JSON_PRETTY_PRINT), "\n";
Expand Down
20 changes: 18 additions & 2 deletions lib/helpers/mail/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,15 @@
class ReplyTo implements \JsonSerializable
{
private $email;
private $name;

public function __construct($email)
public function __construct($email, $name = null)
{
$this->email = $email;

if (!is_null($name)) {
$this->name = $name;
}
}

public function setEmail($email)
Expand All @@ -31,11 +36,22 @@ public function getEmail()
return $this->email;
}

public function setName($name)
{
$this->name = $name;
}

public function getName()
{
return $this->name;
}

public function jsonSerialize()
{
return array_filter(
[
'email' => $this->getEmail()
'email' => $this->getEmail(),
'name' => $this->getName(),
],
function ($value) {
return $value !== null;
Expand Down
14 changes: 14 additions & 0 deletions test/unit/helpers/mail/MailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,25 @@ public function testKitchenSinkExample()
$tracking_settings->setGanalytics($ganalytics);
$mail->setTrackingSettings($tracking_settings);

$reply_to = new ReplyTo("[email protected]", "Optional Name");
$mail->setReplyTo($reply_to);

$json = json_encode($mail);

$this->assertEquals($json, '{"from":{"name":"DX","email":"[email protected]"},"personalizations":[{"to":[{"name":"Example User","email":"[email protected]"},{"name":"Example User","email":"[email protected]"}],"cc":[{"name":"Example User","email":"[email protected]"},{"name":"Example User","email":"[email protected]"}],"bcc":[{"name":"Example User","email":"[email protected]"},{"name":"Example User","email":"[email protected]"}],"subject":"Hello World from the SendGrid PHP Library","headers":{"X-Test":"test","X-Mock":"true"},"substitutions":{"%name%":"Example User","%city%":"Denver"},"custom_args":{"user_id":"343","type":"marketing"},"send_at":1443636843},{"to":[{"name":"Example User","email":"[email protected]"},{"name":"Example User","email":"[email protected]"}],"cc":[{"name":"Example User","email":"[email protected]"},{"name":"Example User","email":"[email protected]"}],"bcc":[{"name":"Example User","email":"[email protected]"},{"name":"Example User","email":"[email protected]"}],"subject":"Hello World from the SendGrid PHP Library","headers":{"X-Test":"test","X-Mock":"true"},"substitutions":{"%name%":"Example User","%city%":"Denver"},"custom_args":{"user_id":"343","type":"marketing"},"send_at":1443636843}],"subject":"Hello World from the SendGrid PHP Library","content":[{"type":"text\/plain","value":"some text here"},{"type":"text\/html","value":"<html><body>some text here<\/body><\/html>"}],"attachments":[{"content":"TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gQ3JhcyBwdW12","type":"application\/pdf","filename":"balance_001.pdf","disposition":"attachment","content_id":"Balance Sheet"},{"content":"BwdW","type":"image\/png","filename":"banner.png","disposition":"inline","content_id":"Banner"}],"template_id":"439b6d66-4408-4ead-83de-5c83c2ee313a","sections":{"%section1%":"Substitution Text for Section 1","%section2%":"Substitution Text for Section 2"},"headers":{"X-Test1":"1","X-Test2":"2"},"categories":["May","2016"],"custom_args":{"campaign":"welcome","weekday":"morning"},"send_at":1443636842,"asm":{"group_id":99,"groups_to_display":[4,5,6,7,8]},"ip_pool_name":"23","mail_settings":{"bcc":{"enable":true,"email":"[email protected]"},"bypass_list_management":{"enable":true},"footer":{"enable":true,"text":"Footer Text","html":"<html><body>Footer Text<\/body><\/html>"},"sandbox_mode":{"enable":true},"spam_check":{"enable":true,"threshold":1,"post_to_url":"https:\/\/spamcatcher.sendgrid.com"}},"tracking_settings":{"click_tracking":{"enable":true,"enable_text":true},"open_tracking":{"enable":true,"substitution_tag":"Optional tag to replace with the open image in the body of the message"},"subscription_tracking":{"enable":true,"text":"text to insert into the text\/plain portion of the message","html":"<html><body>html to insert into the text\/html portion of the message<\/body><\/html>","substitution_tag":"Optional tag to replace with the open image in the body of the message"},"ganalytics":{"enable":true,"utm_source":"some source","utm_medium":"some medium","utm_term":"some term","utm_content":"some content","utm_campaign":"some name"}},"reply_to":{"email":"[email protected]","name":"Optional Name"}}');

$reply_to = new ReplyTo("[email protected]");
$mail->setReplyTo($reply_to);

$json = json_encode($mail);

$this->assertEquals($json, '{"from":{"name":"DX","email":"[email protected]"},"personalizations":[{"to":[{"name":"Example User","email":"[email protected]"},{"name":"Example User","email":"[email protected]"}],"cc":[{"name":"Example User","email":"[email protected]"},{"name":"Example User","email":"[email protected]"}],"bcc":[{"name":"Example User","email":"[email protected]"},{"name":"Example User","email":"[email protected]"}],"subject":"Hello World from the SendGrid PHP Library","headers":{"X-Test":"test","X-Mock":"true"},"substitutions":{"%name%":"Example User","%city%":"Denver"},"custom_args":{"user_id":"343","type":"marketing"},"send_at":1443636843},{"to":[{"name":"Example User","email":"[email protected]"},{"name":"Example User","email":"[email protected]"}],"cc":[{"name":"Example User","email":"[email protected]"},{"name":"Example User","email":"[email protected]"}],"bcc":[{"name":"Example User","email":"[email protected]"},{"name":"Example User","email":"[email protected]"}],"subject":"Hello World from the SendGrid PHP Library","headers":{"X-Test":"test","X-Mock":"true"},"substitutions":{"%name%":"Example User","%city%":"Denver"},"custom_args":{"user_id":"343","type":"marketing"},"send_at":1443636843}],"subject":"Hello World from the SendGrid PHP Library","content":[{"type":"text\/plain","value":"some text here"},{"type":"text\/html","value":"<html><body>some text here<\/body><\/html>"}],"attachments":[{"content":"TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gQ3JhcyBwdW12","type":"application\/pdf","filename":"balance_001.pdf","disposition":"attachment","content_id":"Balance Sheet"},{"content":"BwdW","type":"image\/png","filename":"banner.png","disposition":"inline","content_id":"Banner"}],"template_id":"439b6d66-4408-4ead-83de-5c83c2ee313a","sections":{"%section1%":"Substitution Text for Section 1","%section2%":"Substitution Text for Section 2"},"headers":{"X-Test1":"1","X-Test2":"2"},"categories":["May","2016"],"custom_args":{"campaign":"welcome","weekday":"morning"},"send_at":1443636842,"asm":{"group_id":99,"groups_to_display":[4,5,6,7,8]},"ip_pool_name":"23","mail_settings":{"bcc":{"enable":true,"email":"[email protected]"},"bypass_list_management":{"enable":true},"footer":{"enable":true,"text":"Footer Text","html":"<html><body>Footer Text<\/body><\/html>"},"sandbox_mode":{"enable":true},"spam_check":{"enable":true,"threshold":1,"post_to_url":"https:\/\/spamcatcher.sendgrid.com"}},"tracking_settings":{"click_tracking":{"enable":true,"enable_text":true},"open_tracking":{"enable":true,"substitution_tag":"Optional tag to replace with the open image in the body of the message"},"subscription_tracking":{"enable":true,"text":"text to insert into the text\/plain portion of the message","html":"<html><body>html to insert into the text\/html portion of the message<\/body><\/html>","substitution_tag":"Optional tag to replace with the open image in the body of the message"},"ganalytics":{"enable":true,"utm_source":"some source","utm_medium":"some medium","utm_term":"some term","utm_content":"some content","utm_campaign":"some name"}},"reply_to":{"email":"[email protected]"}}');

$reply_to = new ReplyTo("[email protected]", null);
$mail->setReplyTo($reply_to);

$json = json_encode($mail);

$this->assertEquals($json, '{"from":{"name":"DX","email":"[email protected]"},"personalizations":[{"to":[{"name":"Example User","email":"[email protected]"},{"name":"Example User","email":"[email protected]"}],"cc":[{"name":"Example User","email":"[email protected]"},{"name":"Example User","email":"[email protected]"}],"bcc":[{"name":"Example User","email":"[email protected]"},{"name":"Example User","email":"[email protected]"}],"subject":"Hello World from the SendGrid PHP Library","headers":{"X-Test":"test","X-Mock":"true"},"substitutions":{"%name%":"Example User","%city%":"Denver"},"custom_args":{"user_id":"343","type":"marketing"},"send_at":1443636843},{"to":[{"name":"Example User","email":"[email protected]"},{"name":"Example User","email":"[email protected]"}],"cc":[{"name":"Example User","email":"[email protected]"},{"name":"Example User","email":"[email protected]"}],"bcc":[{"name":"Example User","email":"[email protected]"},{"name":"Example User","email":"[email protected]"}],"subject":"Hello World from the SendGrid PHP Library","headers":{"X-Test":"test","X-Mock":"true"},"substitutions":{"%name%":"Example User","%city%":"Denver"},"custom_args":{"user_id":"343","type":"marketing"},"send_at":1443636843}],"subject":"Hello World from the SendGrid PHP Library","content":[{"type":"text\/plain","value":"some text here"},{"type":"text\/html","value":"<html><body>some text here<\/body><\/html>"}],"attachments":[{"content":"TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVyIGFkaXBpc2NpbmcgZWxpdC4gQ3JhcyBwdW12","type":"application\/pdf","filename":"balance_001.pdf","disposition":"attachment","content_id":"Balance Sheet"},{"content":"BwdW","type":"image\/png","filename":"banner.png","disposition":"inline","content_id":"Banner"}],"template_id":"439b6d66-4408-4ead-83de-5c83c2ee313a","sections":{"%section1%":"Substitution Text for Section 1","%section2%":"Substitution Text for Section 2"},"headers":{"X-Test1":"1","X-Test2":"2"},"categories":["May","2016"],"custom_args":{"campaign":"welcome","weekday":"morning"},"send_at":1443636842,"asm":{"group_id":99,"groups_to_display":[4,5,6,7,8]},"ip_pool_name":"23","mail_settings":{"bcc":{"enable":true,"email":"[email protected]"},"bypass_list_management":{"enable":true},"footer":{"enable":true,"text":"Footer Text","html":"<html><body>Footer Text<\/body><\/html>"},"sandbox_mode":{"enable":true},"spam_check":{"enable":true,"threshold":1,"post_to_url":"https:\/\/spamcatcher.sendgrid.com"}},"tracking_settings":{"click_tracking":{"enable":true,"enable_text":true},"open_tracking":{"enable":true,"substitution_tag":"Optional tag to replace with the open image in the body of the message"},"subscription_tracking":{"enable":true,"text":"text to insert into the text\/plain portion of the message","html":"<html><body>html to insert into the text\/html portion of the message<\/body><\/html>","substitution_tag":"Optional tag to replace with the open image in the body of the message"},"ganalytics":{"enable":true,"utm_source":"some source","utm_medium":"some medium","utm_term":"some term","utm_content":"some content","utm_campaign":"some name"}},"reply_to":{"email":"[email protected]"}}');
}
}

0 comments on commit 0e9fde3

Please sign in to comment.