Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions EmailNewUser.module.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ static public function getDefaultData() {
"automaticEmailSend" => 1,
"fromEmail" => wire('config')->adminEmail,
"fromName" => "",
"replyToEmail" => "",
"replyToName" => "",
"bccEmail" => "",
"addParam" => "",
"generatePassword" => "",
Expand Down Expand Up @@ -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."));
}
Expand All @@ -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'] != '') {
Expand All @@ -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);
Expand Down Expand Up @@ -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."));
}
Expand All @@ -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;
Expand All @@ -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');
Expand Down