From 1093901913737987d0a29c12f6655b4fbd274dd3 Mon Sep 17 00:00:00 2001 From: James Ellis Date: Fri, 9 Feb 2018 12:48:23 +1100 Subject: [PATCH] Support alwaysFrom handling in config, update job title to show From address --- src/jobs/SendJob.php | 5 ++++- src/mailer/Mailer.php | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/jobs/SendJob.php b/src/jobs/SendJob.php index 43fd0a0..bae7b3a 100644 --- a/src/jobs/SendJob.php +++ b/src/jobs/SendJob.php @@ -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() { diff --git a/src/mailer/Mailer.php b/src/mailer/Mailer.php index 94988c9..003778c 100644 --- a/src/mailer/Mailer.php +++ b/src/mailer/Mailer.php @@ -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} @@ -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);