From 53d3433381df1905d00d3fa4cc45e04addbe7339 Mon Sep 17 00:00:00 2001 From: Jonathan Lahijani Date: Mon, 3 Jun 2024 10:43:48 -0700 Subject: [PATCH 1/2] add support from replyToEmail and replyToName --- EmailNewUser.module.php | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/EmailNewUser.module.php b/EmailNewUser.module.php index 9494646..26fc004 100644 --- a/EmailNewUser.module.php +++ b/EmailNewUser.module.php @@ -44,6 +44,8 @@ static public function getDefaultData() { "automaticEmailSend" => 1, "fromEmail" => wire('config')->adminEmail, "fromName" => "", + "replyToEmail" => "", + "replyToName" => "", "bccEmail" => "", "addParam" => "", "generatePassword" => "", @@ -121,7 +123,7 @@ protected function addEmailFields(HookEvent $event) { $f->attr('name', 'sendEmail'); $f->notes = $notes; $f->label = $sendLabel; - $f->showIf = "email!='', roles.count>1"; + //$f->showIf = "email!='', roles.count>1"; $f->attr('checked', $checked); $f->collapsed = Inputfield::collapsedBlank; $form->append($f); @@ -200,7 +202,7 @@ protected function prepareNewUserEmail(HookEvent $event) { $this->wire()->error($this->_("No email was sent to the new user because either their email address or password was not set.")); } else{ - $sent = $this->sendNewUserEmail($page->email, $this->data['fromEmail'], $this->data['fromName'], $this->data['subject'.$this->lang], $htmlBody); + $sent = $this->sendNewUserEmail($page->email, $this->data['fromEmail'], $this->data['fromName'], $this->data['subject'.$this->lang], $htmlBody, $this->data['replyToEmail'], $this->data['replyToName']); if($sent) { $this->wire()->message($this->_("{$page->name} was successfully sent a welcome email.")); } @@ -212,7 +214,7 @@ protected function prepareNewUserEmail(HookEvent $event) { } - private function sendNewUserEmail($to, $fromEmail, $fromName, $subject, $htmlBody) { + private function sendNewUserEmail($to, $fromEmail, $fromName, $subject, $htmlBody, $replyToEmail=false, $replyToName=false) { $mailer = $this->wire('mail') ? $this->wire('mail')->new() : wireMail(); $mailer->to($to); if($this->data['bccEmail'] != '') { @@ -225,6 +227,9 @@ private function sendNewUserEmail($to, $fromEmail, $fromName, $subject, $htmlBod } $mailer->from($fromEmail); $mailer->fromName($fromName); + if($replyToEmail) { + $mailer->replyTo($replyToEmail, $replyToName); + } $mailer->subject($subject); $mailer->body($this->parseTextBody($htmlBody)); $mailer->bodyHTML($htmlBody); @@ -386,7 +391,7 @@ public function getModuleConfigInputfields(array $data) { // send test email if requested if ($this->wire('input')->post->test) { - $sent = $this->sendNewUserEmail($this->wire('user')->email, $data['fromEmail'], $data['fromName'], $data['subject'.$this->lang], $this->parseBody($data['body'.$this->lang], $data['fromEmail'], $this->wire('user'), 'password')); + $sent = $this->sendNewUserEmail($this->wire('user')->email, $data['fromEmail'], $data['fromName'], $data['subject'.$this->lang], $this->parseBody($data['body'.$this->lang], $data['fromEmail'], $this->wire('user'), 'password'), $data['replyToEmail'], $data['replyToName']); if($sent) { $this->wire()->message($this->_("Test email was sent successfully.")); } @@ -409,7 +414,7 @@ public function getModuleConfigInputfields(array $data) { $f = $this->wire('modules')->get("InputfieldEmail"); $f->attr('name', 'fromEmail'); - $f->label = __('From email address'); + $f->label = __('From Email Address'); $f->description = __('Email address that the email will come from.'); $f->notes = __("If this field is blank, the email will not be sent."); $f->columnWidth = 50; @@ -424,6 +429,20 @@ public function getModuleConfigInputfields(array $data) { $f->value = $data['fromName']; $wrapper->add($f); + $f = $this->wire('modules')->get("InputfieldEmail"); + $f->attr('name', 'replyToEmail'); + $f->label = __('Reply To Email Address'); + $f->columnWidth = 50; + $f->value = $data['replyToEmail']; + $wrapper->add($f); + + $f = $this->wire('modules')->get("InputfieldText"); + $f->attr('name', 'replyToName'); + $f->label = __('Reply To Name'); + $f->columnWidth = 50; + $f->value = $data['replyToName']; + $wrapper->add($f); + $f = $this->wire('modules')->get("InputfieldText"); $f->attr('name', 'bccEmail'); $f->label = __('Notify Other Users'); From 49cc9865f04583edb1e77d19f5af28519d17aee9 Mon Sep 17 00:00:00 2001 From: Jonathan Lahijani Date: Mon, 3 Jun 2024 10:49:34 -0700 Subject: [PATCH 2/2] remove accidental comment --- EmailNewUser.module.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/EmailNewUser.module.php b/EmailNewUser.module.php index 26fc004..541b0c9 100644 --- a/EmailNewUser.module.php +++ b/EmailNewUser.module.php @@ -123,7 +123,7 @@ protected function addEmailFields(HookEvent $event) { $f->attr('name', 'sendEmail'); $f->notes = $notes; $f->label = $sendLabel; - //$f->showIf = "email!='', roles.count>1"; + $f->showIf = "email!='', roles.count>1"; $f->attr('checked', $checked); $f->collapsed = Inputfield::collapsedBlank; $form->append($f);