title: Contact Form Mailer in Rails 4
body: <p>I am trying to build a contact form in Rails 4, where the form takes a name, email, and body and sends it to my email address. Upon clicking "Submit", the app redirects back to the Contact page correctly, but no email appears to get sent.</p>
  
  <h3>routes.rb</h3>
  
  <pre><code>match '/send_mail', to: 'contact#send_mail', via: 'post'
  </code></pre>
  
  <h3>contact_email.html.erb</h3>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;%= stylesheet_link_tag    "application", media: "all", "data-turbolinks-track" =&gt; true %&gt;
          &lt;%= javascript_include_tag "application", "data-turbolinks-track" =&gt; true %&gt;
          &lt;meta name="viewport" content="width=device-width, initial-scale=1.0"&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;p&gt;You have received the following email from &lt;%= "#{ @name } (#{ @email }):" %&gt;&lt;/p&gt;
          &lt;p&gt;&lt;%= @body %&gt;&lt;/p&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <h3>contact_controller.rb</h3>
  
  <pre><code>def send_mail
      name = params[:name]
      email = params[:email]
      body = params[:comments]
      ContactMailer.contact_email(name, email, body).deliver
      redirect_to contact_path, notice: 'Message sent'
  end
  </code></pre>
  
  <h3>contact_mailer.rb</h3>
  
  <pre><code>class ContactMailer &lt; ActionMailer::Base
      default to: # my email address
  
      def contact_email(name, email, body)
          @name = name
          @email = email
          @body = body`enter code here`
  
          mail(from: email, subject: 'Contact Request')
      end
  end
  </code></pre>
  
  <h3>contact.html.erb</h3>
  
  <pre><code>&lt;div class="container-content"&gt;
      &lt;div class="container"&gt;
          &lt;%= form_tag(send_mail_path) do %&gt;
              &lt;div class="form-group"&gt;
                  &lt;%= label_tag 'name', 'Name' %&gt;
                  &lt;%= text_field_tag 'name', nil, class: 'form-control', placeholder: 'Your Name' %&gt;
              &lt;/div&gt;
             &lt;div class="form-group"&gt;
                 &lt;%= label_tag 'email', 'Email' %&gt;
                 &lt;%= email_field_tag 'email', nil, class: 'form-control', placeholder: 'Your Email Address' %&gt;
             &lt;/div&gt;
             &lt;div class="form-group"&gt;
                 &lt;%= label_tag 'comments', 'Comments' %&gt;
                 &lt;%= text_area_tag 'comments', nil, class: 'form-control', rows: 4, placeholder: 'Comments...' %&gt;
             &lt;/div&gt;
             &lt;%= submit_tag nil, class: 'btn btn-default btn-about pull-right' %&gt;
         &lt;% end %&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <h3>application.rb</h3>
  
  <pre><code>config.action_mailer.delivery_method = :sendmail
  config.action_mailer.perform_deliveries = true
  config.action_mailer.raise_delivery_errors = true
  </code></pre>