Skip to content

Instantly share code, notes, and snippets.

@digitalpardoe
Created July 16, 2011 17:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save digitalpardoe/1086543 to your computer and use it in GitHub Desktop.
Save digitalpardoe/1086543 to your computer and use it in GitHub Desktop.
An Email Form with Ruby on Rails
<% form_for :email, :url => { :controller => 'contact', :action => 'send_mail' } do |f| %>
<%= f.label :name %><br />
<%= f.text_field :name, :size => 60 %><br />
<%= f.label :address %><br />
<%= f.text_field :address, :size => 60 %><br />
<%= f.label :subject %><br />
<%= f.text_field :subject, :size => 60 %><br />
<%= f.label :body %><br />
<%= f.text_area :body, :rols => 10, :cols => 60 %><br />
<%= submit_tag "Send Email "%>
<% end %>
def send_mail
Emailer::deliver_contact_email(params[:email])
end
<p>Name:</p>
<p><%= @email_name %></p>
<p>Message:</p>
<p><%= @email_body %></p>
class Emailer < ActionMailer::Base
def contact_email(email_params)
# You only need to customize @recipients.
@recipients = "contact@website.co.uk"
@from = email_params[:name] + " <" + email_params[:address] + ">"
@subject = email_params[:subject]
@sent_on = Time.now
@body["email_body"] = email_params[:body]
@body["email_name"] = email_params[:name]
content_type "text/html"
end
end
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => 'localhost',
:domain => 'website.co.uk',
:port => 25,
:authentication => :login,
:user_name => "smtp_username",
:password => "smtp_password"
}
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = false
config.action_mailer.default_charset = "utf-8"
./script/generate mailer Emailer
cd /rails_app
@niti19
Copy link

niti19 commented Dec 11, 2015

I want this example withcontroller and index

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment