Example #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'));
     }
 }
Example #2
0
echo Form::renderTokenInput();
?>

    <p>Contact Us:</p>

    <input type="hidden" name="action" value="sendMessage" />

    Your Name:<br />
    <input type="text" name="name" id='name' value="<?php 
echo Field::defaultValue('name');
?>
" class="required" /><br />

    Your Email:<br />
    <input type="text" name="email" id='my_email' value="<?php 
echo Field::defaultValue('email');
?>
" class="required email" /><br />

    Your message:<br />
    <textarea name="message" cols="70" rows="20"><?php 
echo Field::defaultValue('name', null, 'text');
?>
</textarea><br />
    <?php 
echo ReCaptcha::render();
?>
    <br />
    <input type="Submit" name="Submit" value="Send Message" class="button" />
</form>