I’ve been working on a contact form, however, most of the examples I see
posted are outdated and I’m just having some trouble getting this to
work. Here’s what I’ve done so far:
At the bottom of my environment.rb file I’ve placed:
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address => “mail.ncaastatpages.com”,
:port => 25,
:domain => “ncaastatpages.com”
}
==========================================
In mail.yml within config I’ve placed the following:
development:
:address: mail.ncaastatpages.com
:port: 25
:authentication: plain
:user_name: [email protected]
:password: mypassword
I created a mailer model which contains the method for notifications
def notifications(sent_at = Time.now)
subject params[:subject]
recipients ‘[email protected]’
from params[:address]
sent_on sent_at
body :greeting => params[:body], :sender_name => params[:name]
end
==========================================
I created the contact controller which contains:
class ContactController < ApplicationController
def index
# render index.html.erb
end
def send_mail
Mailer.deliver_notifications(params[:email])
flash[:notice] = “Email was succesfully sent.”
redirect_to :action => “index”
end
end
===========================================
I have the form in my contact view for index.html.erb
<% form_tag :action => "send_mail" do %> <%= label :email, :name, "Name" %><%= text_field :email, :name %> <%= label :email, :address, "Your Email Address" %>
<%= text_field :email, :address %> <%= label :email, :subject, "Subject" %>
<%= text_field :email, :subject %> <%= label :email, :body, "Your Message" %>
<%= text_area :email, :body, :rows => 8, :cols => 50 %> <%= submit_tag "Submit" %> <% end %>
==================================================
I added the following map route:
map.contact ‘/contact/send_mail’, :controller => ‘contact’, :action =>
‘send_mail’
==================================================
I go to the contacts page and see the form fine.
When I enter the information and submit I receive the following error:
undefined local variable or method `params’ for #Mailer:0x3c9d6f8
It shows contact_controller.rb:7:in `send_mail’
which contains…
Mailer.deliver_notifications(params[:email])
==================================================
I know I’m probably doing a few things wrong but mailing seems to be a
very difficult process for me to learn. Any help would be appreciated.
Thanks.