Hello, I am trying to make a very basic "contact me" form on my website. I have tried the following tutorials: http://railsforum.com/viewtopic.php?id=15172 http://railsforum.com/viewtopic.php?id=404 http://forums.site5.com/showthread.php?t=18522 http://www.buildingwebapps.com/podcasts/6798-adding-a-contact-form-and-mailer/show_notes http://digitalpardoe.co.uk/blog/show/56 I found the last one to fit my needs the best. I need to have forms for a person''s name, email address and message. Upon clicking a submit button, I want that information emailed to a hardcoded email address. My setup is as follows: /config/environment.rb: [code=] ... (at the end) ActionMailer::Base.delivery_method = :smtp ActionMailer::Base.server_settings = { :address => ''localhost'', #was told by hostgator that these are the correct settings :port => 25, :authentication => :login, # Don''t change this one. :user_name => "mailer_username", :password => "mailer_password" } ActionMailer::Base.perform_deliveries = true ActionMailer::Base.raise_delivery_errors = true ActionMailer::Base.default_charset = "utf-8" [/code] /app/models/emailer.rb: [code=] class Emailer < ActionMailer::Base def contact_email(email_params, sent_at = Time.now) # You only need to customize @recipients. @recipients = "myemail-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org" @from = email_params[:name] + " <" + @email_params[:address] + ">" @subject = email_params[:subject] @sent_on = sent_at @body["email_body"] = email_params[:body] @body["email_name"] = email_params[:name] end end [/code] /app/controllers/emailer_controller.rb [code=] class EmailerController < ApplicationController def send_mail Emailer::deliver_contact_email(params[:email]) end end[/code] /app/views/emailer/contact_email.rhtml (this is the formatting of the message sent) [code=] Name: <%= @email_name %> Message: <%= @email_body %> [/code] /app/views/emailer/contact_page.rhtml (this is the form from which the message is made) [code=] <% form_tag :action => "send_mail" do %> <table> <tr> <td><label for="email_name">Name:</label></td> <td><%= text_field "email", "name", :size => 30 %></td> </tr> <tr> <td><label for="email_address">Email Address:</label></td> <td><%= text_field "email", "address", :size => 30 %></td> </tr> <tr> <td><label for="email_subject">Subject:</label></td> <td><%= text_field "email", "subject", :size => 30 %></td> </tr> <tr> <td><label for="email_body">Body:</label></td> <td><%= text_area "email", "body", :rows => 8, :cols => 30 %></td> </tr> </table> <input type="submit" value="Send Email" class="primary" /> <% end %> [/code] /app/config/routes.rb: [code=] ... map.connect ''contactme'', :controller => ''emailer'', :action => ''contact_page'' #testing ... [/code] When I fill out the contact forms and send, nothing happens. The only error I was getting with script/server was a depreciation error with the view, but Duplex helped me fix that. I contacted hostgator to see if my settings in environment.rb were correct, and they said they were. So I''m thinking I wasn''t supposed to put the "def send_mail..." in it''s own separate controller? I''m really not sure because this looks right to me. Some other information: I''m using simplelog 2.0.2 as my blogging platform on rails 2.0.2 and I''m trying to add this contact form to it. Simplelog works wonderfully, but maybe its causing problems for the mailer. Another thing, when I change "Base.server_settings" to "Base.smtp_settings" in /config/environment.rb, rails fails to start. I thought "Base.smtp_settings" was the new, better way for that setting. Does anyone have any hints for me on how to get this mailer working? I''ve spent days trying to figure this out, please help. If you read all of that, thank you very much for your time :) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Try modifying your environment.rb to include the following ==... Rails::Initializer.run do |config| # Settings in config/environments/* take precedence over those specified here. # ... ##### start narayan config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { :address => "mail.mydomain.com", :port => "26", :domain => "mydomain.com", :user_name => "abc-3Q2Tfjf0mexWk0Htik3J/w@public.gmane.org", :password => "xxxx", :authentication => :login } ##### end narayan == Hope it works! -Narayan On Oct 23, 8:47 am, Victor Vlist <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Hello, I am trying to make a very basic "contact me" form on my website. > I have tried the following tutorials:http://railsforum.com/viewtopic.php?id=15172http://railsforum.com/viewtopic.php?id=404http://forums.site5.com/showthread.php?t=18522http://www.buildingwebapps.com/podcasts/6798-adding-a-contact-form-an...http://digitalpardoe.co.uk/blog/show/56 > > I found the last one to fit my needs the best. I need to have forms for > a person''s name, email address and message. Upon clicking a submit > button, I want that information emailed to a hardcoded email address. > > My setup is as follows: > > /config/environment.rb: > [code=] > ... (at the end) > ActionMailer::Base.delivery_method = :smtp > ActionMailer::Base.server_settings = { > :address => ''localhost'', #was told by hostgator that these > are the correct settings > :port => 25, > :authentication => :login, # Don''t change this one. > :user_name => "mailer_username", > :password => "mailer_password"} > > ActionMailer::Base.perform_deliveries = true > ActionMailer::Base.raise_delivery_errors = true > ActionMailer::Base.default_charset = "utf-8" > [/code] > /app/models/emailer.rb: > [code=] > class Emailer < ActionMailer::Base > def contact_email(email_params, sent_at = Time.now) > # You only need to customize @recipients. > @recipients = "myem...-hcDgGtZH8xNBDgjK7y7TUQ@public.gmane.org" > @from = email_params[:name] + " <" + @email_params[:address] + ">" > @subject = email_params[:subject] > @sent_on = sent_at > @body["email_body"] = email_params[:body] > @body["email_name"] = email_params[:name] > end > end > [/code] > /app/controllers/emailer_controller.rb > [code=] > class EmailerController < ApplicationController > def send_mail > Emailer::deliver_contact_email(params[:email]) > end > end[/code] > /app/views/emailer/contact_email.rhtml (this is the formatting of the > message sent) > [code=] > Name: > > <%= @email_name %> > > Message: > > <%= @email_body %> > [/code] > /app/views/emailer/contact_page.rhtml (this is the form from which the > message is made) > [code=] > <% form_tag :action => "send_mail" do %> > <table> > <tr> > <td><label for="email_name">Name:</label></td> > <td><%= text_field "email", "name", :size => 30 %></td> > </tr> > <tr> > <td><label for="email_address">Email Address:</label></td> > <td><%= text_field "email", "address", :size => 30 %></td> > </tr> > <tr> > <td><label for="email_subject">Subject:</label></td> > <td><%= text_field "email", "subject", :size => 30 %></td> > </tr> > <tr> > <td><label for="email_body">Body:</label></td> > <td><%= text_area "email", "body", :rows => 8, :cols => 30 > %></td> > </tr> > </table> > > <input type="submit" value="Send Email" class="primary" /> > <% end %> > [/code] > /app/config/routes.rb: > [code=] > ... > map.connect ''contactme'', :controller => ''emailer'', :action => > ''contact_page'' #testing > ... > [/code] > When I fill out the contact forms and send, nothing happens. The only > error I was getting with script/server was a depreciation error with the > view, but Duplex helped me fix that. > > I contacted hostgator to see if my settings in environment.rb were > correct, and they said they were. So I''m thinking I wasn''t supposed to > put the "def send_mail..." in it''s own separate controller? I''m really > not sure because this looks right to me. > > Some other information: I''m using simplelog 2.0.2 as my blogging > platform on rails 2.0.2 and I''m trying to add this contact form to it. > Simplelog works wonderfully, but maybe its causing problems for the > mailer. Another thing, when I change "Base.server_settings" to > "Base.smtp_settings" in /config/environment.rb, rails fails to start. I > thought "Base.smtp_settings" was the new, better way for that setting. > Does anyone have any hints for me on how to get this mailer working? > I''ve spent days trying to figure this out, please help. > > If you read all of that, thank you very much for your time :) > -- > Posted viahttp://www.ruby-forum.com/.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
First of all, thank you for replying. When I use your suggestion I get an "application fails to start" error. I narrowed it down to one thing though. What causes the fails to start error is the "smtp" in the "config.action_mailer.smtp_settings = {" line in /config/environment.rb. If I use "server" as in "config.action_mailer.server_settings = {" The app starts again, but the email doesn''t send. I know the "server_settings" option is now depreciated, so what can be done? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Rake produces the error: undefined method `smtp_settings='' for ActionMailer::Base:Class How do I define that method? Do I put it in environment.rb? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Okay, I just noticed that my code isn''t --exactly-- the same in environment.rb, I left this out: ActionMailer::Base.perform_deliveries = true ActionMailer::Base.raise_delivery_errors = true ActionMailer::Base.default_charset = "utf-8" But when I put it back in the app fails to start. What should my environment.rb look like? (Thank you so much for helping me) -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Narayan wrote:> Not sure why > > it works fine for me, so send me your environment.rb and i can take a > look at it (pls clear the password field ) > > also send me the Rails version no. > > -Narayan > > > On Oct 24, 6:25�am, Victor Vlist <rails-mailing-l...-ARtvInVfO7m5VldFQK4jKA@public.gmane.orgt>Okay, sorry for the delayed reply. Hostgator upgraded rails from 2.0.2 to 2.1.2 last night. So my app wouldn''t start at all. Now I''m rebuilding, and I''m starting with the mailer. I''m using exactly the same code as above and good news. Using smtp now works, but still no email is being sent. Here is my environment.rb. Attachments: http://www.ruby-forum.com/attachment/2851/environment.rb -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---