/**
  * @Request({"email": "string"})
  */
 public function requestAction($email)
 {
     try {
         if (App::user()->isAuthenticated()) {
             return App::redirect();
         }
         if (!App::csrf()->validate()) {
             throw new Exception(__('Invalid token. Please try again.'));
         }
         if (empty($email)) {
             throw new Exception(__('Enter a valid email address.'));
         }
         if (!($user = User::findByEmail($email))) {
             throw new Exception(__('Unknown email address.'));
         }
         if ($user->isBlocked()) {
             throw new Exception(__('Your account has not been activated or is blocked.'));
         }
         $user->activation = App::get('auth.random')->generateString(32);
         $url = App::url('@user/resetpassword/confirm', ['user' => $user->username, 'key' => $user->activation], 0);
         try {
             $mail = App::mailer()->create();
             $mail->setTo($user->email)->setSubject(__('Reset password for %site%.', ['%site%' => App::module('system/site')->config('title')]))->setBody(App::view('system/user:mails/reset.php', compact('user', 'url', 'mail')), 'text/html')->send();
         } catch (\Exception $e) {
             throw new Exception(__('Unable to send confirmation link.'));
         }
         $user->save();
         return ['message' => __('Check your email for the confirmation link.')];
     } catch (Exception $e) {
         App::abort(400, $e->getMessage());
     }
 }
Example #2
0
 /**
  * @return MailHelper
  */
 public function sendMail()
 {
     if (!($adminMail = $this->submission->form->get('submitEmail'))) {
         return $this;
     }
     $user_email = $this->submission->email ?: false;
     $mailSubject = $this->replaceString($this->submission->form->get('email_subject'));
     $mailBody = $this->replaceString($this->submission->form->get('email_body'));
     $mailBody = App::content()->applyPlugins($mailBody, ['submission' => $this->submission, 'markdown' => $this->submission->form->get('email_body_markdown')]);
     try {
         /** @var Message $mail */
         $mail = App::mailer()->create();
         if ($user_email && $this->submission->form->get('use_replyto', 0)) {
             $mail->setReplyTo($user_email);
         }
         $mail->setTo($adminMail)->setSubject($mailSubject)->setBody(App::view('bixie/formmaker/mails/template.php', compact('mailBody')), 'text/html')->send();
         if ($user_email) {
             $mail = App::mailer()->create();
             $mail->setTo($user_email)->setSubject($mailSubject)->setBody(App::view('bixie/formmaker/mails/template.php', compact('mailBody')), 'text/html')->send();
         }
     } catch (\Exception $e) {
         throw new Exception(__('Unable to send confirmation mail.'));
     }
     return $this;
 }
 /**
  * Note: If the mailer is accessed prior to this controller action, this will possibly test the wrong mailer
  *
  * @Request({"option": "array"}, csrf=true)
  */
 public function emailAction($option = [])
 {
     try {
         $config = Arr::merge(App::module('system/mail')->config(), $option);
         $response['success'] = (bool) App::mailer()->create(__('Test email!'), __('Testemail'), $config['from_address'])->send();
         $response['message'] = $response['success'] ? __('Mail successfully sent!') : __('Mail delivery failed!');
     } catch (\Exception $e) {
         $response = ['success' => false, 'message' => sprintf(__('Mail delivery failed! (%s)'), $e->getMessage())];
     }
     return $response;
 }
 /**
  * @return string
  */
 public function sendMail()
 {
     if (!($adminMail = $this->submission->form->get('submitEmail'))) {
         return '';
     }
     $userMail = '';
     $mailSubject = $this->replaceString($this->submission->form->get('email_subject'));
     $mailBody = $this->replaceString($this->submission->form->get('email_body'));
     $mailBody = App::content()->applyPlugins($mailBody, ['submission' => $this->submission, 'markdown' => $this->submission->form->get('email_body_markdown')]);
     try {
         $mail = App::mailer()->create();
         $mail->setTo($adminMail)->setSubject($mailSubject)->setBody(App::view('formmaker:views/mails/template.php', compact('mailBody')), 'text/html')->send();
         if ($this->submission->email) {
             $mail = App::mailer()->create();
             $mail->setTo($this->submission->email)->setSubject($mailSubject)->setBody(App::view('formmaker:views/mails/template.php', compact('mailBody')), 'text/html')->send();
         }
     } catch (\Exception $e) {
         throw new Exception(__('Unable to send confirmation mail.'));
     }
     return $userMail;
 }
 protected function sendApproveMail($user)
 {
     try {
         $mail = App::mailer()->create();
         $mail->setTo(App::module('mail')->config('from_address'))->setSubject(__('Approve an account at %site%.', ['%site%' => App::module('system/site')->config('title')]))->setBody(App::view('system/user:mails/approve.php', compact('user', 'mail')), 'text/html')->send();
     } catch (\Exception $e) {
     }
 }