Skip to content

Commit

Permalink
Support alwaysFrom handling in config, update job title to show From …
Browse files Browse the repository at this point in the history
…address
  • Loading branch information
JamesDPC committed Feb 9, 2018
1 parent 8f2d0a6 commit 1093901
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/jobs/SendJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ public function getJobType() {
}

public function getTitle() {
return 'Email via Mailgun To: ' . $this->parameters['to'] . ' Subject: ' . $this->parameters['subject'];
$to = isset($this->parameters['to']) ? $this->parameters['to'] : '';
$subject = isset($this->parameters['subject']) ? $this->parameters['subject'] : '';
$from = isset($this->parameters['from']) ? $this->parameters['from'] : '';
return "Email via Mailgun To: {$to} From: {$from} Subject: {$subject}";
}

public function getSignature() {
Expand Down
10 changes: 10 additions & 0 deletions src/mailer/Mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class Mailer extends SilverstripeMailer {
protected $is_test_mode = false;// when true, Mailgun receives messages (accepted event) but does not send them to the remote. 'delivered' events are recorded.
protected $tags = [];//Note 4000 limit: http://mailgun-documentation.readthedocs.io/en/latest/user_manual.html#tagging
protected $sender = "";// for setting the sender header

public $alwaysFrom;// when set, override From address, applying From provided to Reply-To header

/**
* {@inheritdoc}
Expand Down Expand Up @@ -72,6 +74,14 @@ protected function sendMessage($to, $from, $subject, $content, $plainContent, $a
$attachments = $this->prepareAttachments($attachments);

$parameters = [];

// check if alwaysFrom is set
if($this->alwaysFrom) {
$parameters['h:Reply-To'] = $from;// set the from as a replyto
$from = $this->alwaysFrom;
$this->setSender($from);//set Sender header to be the new From address
}

// add in o: and v: params
$this->addCustomParameters($parameters, $headers);

Expand Down

0 comments on commit 1093901

Please sign in to comment.