Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add optional Reply-to to Web and SMTP API calls.

  • Loading branch information...
commit e725d5afb30c6fb43556e71f1e3d151f5caa811a 1 parent 6fa6777
@theycallmeswift theycallmeswift authored
View
31 SendGrid/Mail.php
@@ -4,10 +4,11 @@
class Mail
{
-
- private $to_list,
+
+ private $to_list,
$from,
$from_name,
+ $reply_to,
$cc_list,
$bcc_list,
$subject,
@@ -21,8 +22,9 @@ class Mail
public function __construct()
{
$this->from_name = false;
+ $this->reply_to = false;
}
-
+
/**
* _removeFromList
* Given a list of key/value pairs, removes the associated keys
@@ -165,7 +167,28 @@ public function setFromName($name)
$this->from_name = $name;
return $this;
}
-
+
+ /**
+ * getReplyTo
+ * get the reply-to address
+ * @return the reply to address
+ */
+ public function getReplyTo()
+ {
+ return $this->reply_to;
+ }
+
+ /**
+ * setReplyTo
+ * set the reply-to address
+ * @param String $email - the email to reply to
+ * @return the SendGrid\Mail object.
+ */
+ public function setReplyTo($email)
+ {
+ $this->reply_to = $email;
+ return $this;
+ }
/**
* getCc
* get the Carbon Copy list of recipients
View
4 SendGrid/Smtp.php
@@ -76,6 +76,10 @@ protected function _mapToSwift(Mail $mail)
$message->setCc($mail->getCcs());
$message->setBcc($mail->getBccs());
+ if(($replyto = $mail->getReplyTo())) {
+ $message->setReplyTo($replyto);
+ }
+
// determine whether or not we can use SMTP recipients (non header based)
if($mail->useHeaders())
{
View
6 SendGrid/Web.php
@@ -46,6 +46,10 @@ protected function _prepMessageData(Mail $mail)
$params['fromname'] = $fromname;
}
+ if(($replyto = $mail->getReplyTo())) {
+ $params['replyto'] = $replyto;
+ }
+
// determine if we should send our recipients through our headers,
// and set the properties accordingly
if($mail->useHeaders())
@@ -62,7 +66,7 @@ protected function _prepMessageData(Mail $mail)
$params['to'] = $mail->getTos();
}
-
+
if($mail->getAttachments())
{
foreach($mail->getAttachments() as $attachment)
View
12 Test/SendGrid/MailTest.php
@@ -76,6 +76,18 @@ public function testFromNameAccessors()
$this->assertEquals("Swift", $message->getFromName());
}
+ public function testReplyToAccessors()
+ {
+ $message = new SendGrid\Mail();
+
+ // Defaults to false
+ $this->assertFalse($message->getReplyTo());
+
+ $message->setReplyTo("swift@sendgrid.com");
+
+ $this->assertEquals("swift@sendgrid.com", $message->getReplyTo());
+ }
+
public function testCcAccessors()
{
$message = new SendGrid\Mail();
View
6 Test/SendGrid/WebTest.php
@@ -64,13 +64,19 @@ public function testOptionalParamters()
$actual_without_optional_params = $mock->testPrepMessageData($message);
$this->assertArrayNotHasKey('fromname', $actual_without_optional_params);
+ $this->assertArrayNotHasKey('replyto', $actual_without_optional_params);
// Set optional params
$message->setFromName('John Doe');
+ $message->setReplyTo('swift@sendgrid.com');
$actual_with_optional_params = $mock->testPrepMessageData($message);
$this->assertArrayHasKey('fromname', $actual_with_optional_params);
+ $this->assertEquals('John Doe', $actual_with_optional_params['fromname']);
+
+ $this->assertArrayHasKey('replyto', $actual_with_optional_params);
+ $this->assertEquals('swift@sendgrid.com', $actual_with_optional_params['replyto']);
}
public function testSendResponse()
Please sign in to comment.
Something went wrong with that request. Please try again.