Created
July 16, 2011 17:02
-
-
Save digitalpardoe/1086543 to your computer and use it in GitHub Desktop.
An Email Form with Ruby on Rails
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% 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 %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def send_mail | |
Emailer::deliver_contact_email(params[:email]) | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<p>Name:</p> | |
<p><%= @email_name %></p> | |
<p>Message:</p> | |
<p><%= @email_body %></p> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Emailer < ActionMailer::Base | |
def contact_email(email_params) | |
# You only need to customize @recipients. | |
@recipients = "[email protected]" | |
@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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
./script/generate mailer Emailer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cd /rails_app |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I want this example withcontroller and index