How to Create a ‘Contact Us’ Page in Radiant 0.7.1

This post is more of a personal note to myself. 99% is copy/paste from either the Radiant wiki, or the Mailer extension’s github page. I’m notating this because both the Radiant wiki and Mailer’s github page have instructions that confused the hell out of me so I’m consolidating it here after getting it working.

This tutorial assumes you have a freshly bootstrapped Radiant installation. Let’s Go!

1) I like the Ray extension for installing stuff so first we install Ray:

me@coffee-bean:~/railz/radiant$ ./script/extension install ray

2) After Ray installs, we can easily use it to install the Mailer extension:

rake ray:extension:install name=mailer

3) After the Mailer extension is installed, we have to modify ‘config/environment.rb’ so that it is no longer excluding the ActionMailer framework.  Find the line ‘config.frameworks -= [ :action_mailer ]’ and change it to just ‘config.frameworks -= []’.

While environment.rb is open, we need to make one additional change.  We need to add our SMTP settings.

Find the line ResponseCache.defaults[:logger] = ActionController::Base.logger.  If you have not modified enviornment.rb before this time, then it should be Line 84.  Below that line but before the next ‘end’ add the following:

ActionMailer::Base.smtp_settings = {
:address => "smtp.domain.com",
:domain => "domain.com",
:user_name => "[email protected]",
:password => "password",
:authentication => :login
}

4) Create a child off of your Home Page in the Radiant Admin and called it “Contact Us”

5) Open the “Contact Us” page and create 2 parts.  Name the first part ‘mailer’.  Name the second part ’email’.
The ‘mailer’ part holds our mail config stuff.
The ’email’ part is the template for the email that is sent out.  This can be named ’email_html’ if you feel like adding html to the body of your email.  ’email_html’ also supports Textile and Markdown.
The ‘body’ part (body is there by default in any page) is where the actual mailer form will go.

6) Put this in the ’email’ part:

Name From: <r:mailer:get name="name"/>
Email From: <r:mailer:get name="email"/>
Body Message:
<r:mailer:get name="message"/>

7) Put this in the ‘mailer’ part, but NOTE this is YAML so indentation matters (2 spaces):

subject: "Sent from your contact us form"
redirect_to: /contact/thanks-for-contacting-us
from_field: email
recipients:
  - [email protected]

Side note 2, the redirect_to is where the user is sent After submitting the form. Obviously, if you set this to some page, you will need to create that page.

8) Put this in the ‘body’ part (or whatever part you want the actual form to live in):

<r:mailer:form name="contact">
<fieldset>
<legend>Enter your contact information and message.</legend>
<r:text name="name"/> <label for="name">Name</label><br>
<r:text name="email"/> <label for="email">Email</label><br>
<label for="message">Message</label><br>
<r:textarea name="message"/><br>
<input type="submit" value="Send">
</fieldset>
</r:mailer:form>

9) Profit!  Try it out.