Exemple #1
0
 /**
  * Send a posted contact request to the site admin.
  */
 public function postSendMessage()
 {
     // Make sure the sender's email address is valid.
     if (!($sender_email = Request::post('email', 'email'))) {
         Messenger::error('Please enter a valid email address.');
         return $this->get();
     }
     if (!ReCaptcha::verify()) {
         Messenger::error('You did not correctly enter the captcha code.');
         return $this->get();
     }
     $subject = Configuration::get('contact.subject');
     $body = "\nName: {$_POST['name']}\nEmail: {$sender_email}\nMessage:\n{$_POST['message']}";
     $to_addresses = Configuration::get('contact.to');
     $mailer = new Mailer();
     foreach ($to_addresses as $to) {
         $mailer->to($to);
     }
     $sent = $mailer->from($sender_email)->subject($subject)->message($body)->send();
     if (!$sent) {
         Messenger::error('Your message could not be sent. Please try again later');
         return $this->get();
     } else {
         // Send an email to to have them test for spam.
         if ($auto_responder = Configuration::get('contact.auto_responder')) {
             $auto_responder_mailer = new Mailer();
             $result = $auto_responder_mailer->sendOne($auto_responder, UserModel::loadByEmail($sender_email) ?: new UserModel(array('email' => $sender_email)));
             if ($result && Configuration::get('contact.spam_test')) {
                 // Set the notice.
                 Navigation::redirect('/message', array('msg' => 'spam_test'));
             }
         }
         Navigation::redirect('/message', array('msg' => 'contact_sent'));
     }
 }
Exemple #2
0
 /**
  * Send a new random password via email.
  */
 public function sendResetLink()
 {
     // Create a temporary key.
     $reset_key = base64_encode($this->getSalt());
     Database::getInstance()->insert('user_temp_key', array('user_id' => $this->id, 'temp_key' => $reset_key, 'time' => time()), array('temp_key' => $reset_key, 'time' => time()));
     // Send a message.
     $mailer = new Mailer();
     $mailer->to($this->email, $this->fullName())->subject('Password reset')->message('A request was made to reset your password. If you did not make this request, please <a href="' . Configuration::get('web_root') . '/contact' . '">notify us</a>. To reset your password, <a href="' . Configuration::get('web_root') . '/user?action=set-password&key=' . $reset_key . '">click here</a>.');
     return $mailer->send();
 }