# Form Mail

**URL:** <https://www.ruby-forum.com/t/form-mail/96108>\
**Category:** Rails\
**Created:** [June 26, 2006, 2:13pm UTC](https://www.ruby-forum.com/t/form-mail/96108 "2006-06-26T14:13:27Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![robtotheb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/db5fbb/32.png) [@robtotheb](https://www.ruby-forum.com/u/robtotheb)\
**Post date:** [June 26, 2006, 2:13pm UTC](https://www.ruby-forum.com/t/form-mail/96108/1 "2006-06-26T14:13:27Z")

</div>

What is the most RoR friendly way of making a form mailer similar to  
this php one?

[http://tips-scripts.com/?tip=form\_mail#tip](http://tips-scripts.com/?tip=form_mail#tip)

Or is it easier just to use the php with RoR?

---

<div class="post-metadata">

**Author:** ![robtotheb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/db5fbb/32.png) [@robtotheb](https://www.ruby-forum.com/u/robtotheb)\
**Post date:** [June 26, 2006, 2:17pm UTC](https://www.ruby-forum.com/t/form-mail/96108/2 "2006-06-26T14:17:56Z")

</div>

## Sending emails from your Rails app is so easy, however I don’t think that is your point. Rails is not intended for replacing simple scripts like that on your website, but you certainly can. Rails is for building applications. Just look at the docs for ActionMailer.

Timothy J.

---

<div class="post-metadata">

**Author:** ![robtotheb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/db5fbb/32.png) [@robtotheb](https://www.ruby-forum.com/u/robtotheb)\
**Post date:** [June 26, 2006, 6:31pm UTC](https://www.ruby-forum.com/t/form-mail/96108/3 "2006-06-26T18:31:13Z")

</div>

Thanks, I sure its simple if you know how but I can’t work it out and  
the ActionMailer doc doesn’t go into much detail.

what I can’t work out is how connect the users form (with email & text  
area ) in the view to communicate to the actionmailer.

---

<div class="post-metadata">

**Author:** ![robtotheb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/db5fbb/32.png) [@robtotheb](https://www.ruby-forum.com/u/robtotheb)\
**Post date:** [June 26, 2006, 6:40pm UTC](https://www.ruby-forum.com/t/form-mail/96108/4 "2006-06-26T18:40:43Z")

</div>

Rob B. wrote:

> Thanks, I sure its simple if you know how but I can’t work it out and  
> the ActionMailer doc doesn’t go into much detail.
> 
> what I can’t work out is how connect the users form (with email & text  
> area ) in the view to communicate to the actionmailer.

I’ll give you sample code where I use a form to ask for someone’s e-mail  
address then I reset their user-pw:

This is in a model… MailSender.rb

class MailSender \< ActionMailer::Base

def sent(subject, body, from, recipient,sent\_at = Time.now)  
@subject = subject  
@body = body  
@recipients = recipient  
@from = from  
@sent\_on = sent\_at  
end  
end

Here is the form in a partial:

 Please Supply Email: \<%= start\_form\_tag :action =\> :rpass%\> \<%= text\_field\_tag :email, params[:email] %\> \<%= submit\_tag "Reset" %\> \<%= end\_form\_tag %\>

Here is the rpass action in the controller:

def rpass  
@email = params[:email]  
@thisUser = User.find(:all, :conditions =\> “email=’#{@email}’”)  
if @thisUser[0]!=nil  
@random = rand(1000000000).to\_s  
@thisUser[0].change\_password(@random)  
@thisUser[0].update()  
@thisUser[0].save  
@message = "Hello - Your password has been reset to: " + @random  
flash[:notice] = “Your password has been changed!”  
email = MailSender.create\_sent(“Password Reset”, @message,  
@thisUser[0].email, removed\_email\_address@domain.invalid)  
MailSender.deliver(email)  
else  
flash[:notice] = “No User with that e-mail”  
end  
redirect\_to :controller =\> “account”, :action =\> “index”  
end

Hope this helps  
-Ben

---

<div class="post-metadata">

**Author:** ![robtotheb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/db5fbb/32.png) [@robtotheb](https://www.ruby-forum.com/u/robtotheb)\
**Post date:** [June 26, 2006, 9:18pm UTC](https://www.ruby-forum.com/t/form-mail/96108/5 "2006-06-26T21:18:51Z")

</div>

Brian H. wrote:

> See an article I wrote on how to handle forms with validations.
> 
> [http://www.bphogan.com/learn/pdf/tableless\_contact\_form.pdf](http://www.bphogan.com/learn/pdf/tableless_contact_form.pdf)

Brian H. you are a Legend! I have been looking for something like  
this for about 4 days now.

You should add this to the Rails Wiki. Its on the wishlist  
[http://wiki.rubyonrails.org/rails/pages/WishList](http://wiki.rubyonrails.org/rails/pages/WishList)

Thanks again!

David S.

---

<div class="post-metadata">

**Author:** ![robtotheb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/db5fbb/32.png) [@robtotheb](https://www.ruby-forum.com/u/robtotheb)\
**Post date:** [June 27, 2006, 11:11am UTC](https://www.ruby-forum.com/t/form-mail/96108/6 "2006-06-27T11:11:31Z")

</div>

> Brian H. wrote:
> 
> > [http://www.bphogan.com/learn/pdf/tableless\_contact\_form.pdf](http://www.bphogan.com/learn/pdf/tableless_contact_form.pdf)

Great - exactly what I needed. Huge thank you!

---

<div class="post-metadata">

**Author:** ![robtotheb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/db5fbb/32.png) [@robtotheb](https://www.ruby-forum.com/u/robtotheb)\
**Post date:** [June 26, 2006, 8:04pm UTC](https://www.ruby-forum.com/t/form-mail/96108/7 "2006-06-26T20:04:11Z")

</div>

See an article I wrote on how to handle forms with validations.

[http://www.bphogan.com/learn/pdf/tableless\_contact\_form.pdf](http://www.bphogan.com/learn/pdf/tableless_contact_form.pdf)

---

<div class="post-metadata">

**Author:** ![robtotheb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/db5fbb/32.png) [@robtotheb](https://www.ruby-forum.com/u/robtotheb)\
**Post date:** [June 27, 2006, 2:12pm UTC](https://www.ruby-forum.com/t/form-mail/96108/8 "2006-06-27T14:12:14Z")

</div>

Even though it’s acknowledged in the article I posted, it wouldn’t have  
been  
possible without the inspiration from Rick O… Thanks Rick!

---

<div class="post-metadata">

**Author:** ![robtotheb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/db5fbb/32.png) [@robtotheb](https://www.ruby-forum.com/u/robtotheb)\
**Post date:** [June 30, 2006, 3:42am UTC](https://www.ruby-forum.com/t/form-mail/96108/9 "2006-06-30T03:42:38Z")

</div>

Rob B. wrote:

> > Brian H. wrote:
> > 
> > > [http://www.bphogan.com/learn/pdf/tableless\_contact\_form.pdf](http://www.bphogan.com/learn/pdf/tableless_contact_form.pdf)

I ran into a problem that I can’t solve.

When I click on Submit I get the following error:  
NoMethodError in #

undefined method `const\_available?’ for FrontController:Class

RAILS\_ROOT: ./script/…/config/…  
Application Trace | Framework Trace | Full Trace

c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action\_controller/routing.rb:234:in  
`traverse_to_controller' generated/routing/recognition.rb:3:in `recognize\_path’  
-e:3:in `load’  
-e:3

c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action\_controller/routing.rb:234:in  
`traverse_to_controller' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action_controller/routing.rb:458:in `recognize!’  
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/dispatcher.rb:38:in  
`dispatch' c:/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/webrick_server.rb:117:in `handle\_dispatch’  
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/webrick\_server.rb:83:in  
`service' c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in `service’  
c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in `run' c:/ruby/lib/ruby/1.8/webrick/server.rb:155:in `start\_thread’  
c:/ruby/lib/ruby/1.8/webrick/server.rb:144:in `start' c:/ruby/lib/ruby/1.8/webrick/server.rb:144:in `start\_thread’  
c:/ruby/lib/ruby/1.8/webrick/server.rb:94:in `start' c:/ruby/lib/ruby/1.8/webrick/server.rb:89:in `each’  
c:/ruby/lib/ruby/1.8/webrick/server.rb:89:in `start' c:/ruby/lib/ruby/1.8/webrick/server.rb:79:in `start’  
c:/ruby/lib/ruby/1.8/webrick/server.rb:79:in `start' c:/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/webrick_server.rb:69:in `dispatch’  
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/commands/servers/webrick.rb:59  
c:/ruby/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:21:in  
`require__' c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in `require’  
c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active\_support/dependencies.rb:214:in  
`require' c:/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/commands/server.rb:28 c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in `require\_\_’  
c:/ruby/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:21:in  
`require' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:214:in `require’  
./script/server:3

c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action\_controller/routing.rb:234:in  
`traverse_to_controller' generated/routing/recognition.rb:3:in `recognize\_path’  
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.11.2/lib/action\_controller/routing.rb:458:in  
`recognize!' c:/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/dispatcher.rb:38:in `dispatch’  
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/webrick\_server.rb:117:in  
`handle_dispatch' c:/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/webrick_server.rb:83:in `service’  
c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in `service' c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in `run’  
c:/ruby/lib/ruby/1.8/webrick/server.rb:155:in `start_thread' c:/ruby/lib/ruby/1.8/webrick/server.rb:144:in `start’  
c:/ruby/lib/ruby/1.8/webrick/server.rb:144:in `start_thread' c:/ruby/lib/ruby/1.8/webrick/server.rb:94:in `start’  
c:/ruby/lib/ruby/1.8/webrick/server.rb:89:in `each' c:/ruby/lib/ruby/1.8/webrick/server.rb:89:in `start’  
c:/ruby/lib/ruby/1.8/webrick/server.rb:79:in `start' c:/ruby/lib/ruby/1.8/webrick/server.rb:79:in `start’  
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/webrick\_server.rb:69:in  
`dispatch' c:/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/commands/servers/webrick.rb:59 c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in `require\_\_’  
c:/ruby/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:21:in  
`require' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active_support/dependencies.rb:214:in `require’  
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.0.0/lib/commands/server.rb:28  
c:/ruby/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:21:in  
`require__' c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in `require’  
c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.2.5/lib/active\_support/dependencies.rb:214:in  
`require' ./script/server:3 -e:3:in `load’  
-e:3

Request

Parameters: {“commit”=\>“Send”, “contact”=\>{“name”=\>“”, “message”=\>“”,  
“subject”=\>“”, “email\_address”=\>“”}}

Any ideas on what its looking for. My code looks exactly like Brian’s

---

<div class="post-metadata">

**Author:** ![robtotheb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/db5fbb/32.png) [@robtotheb](https://www.ruby-forum.com/u/robtotheb)\
**Post date:** [June 30, 2006, 5:45am UTC](https://www.ruby-forum.com/t/form-mail/96108/10 "2006-06-30T05:45:38Z")

</div>

David S. wrote:

> Rob B. wrote:
> 
> > > Brian H. wrote:
> > > 
> > > > [http://www.bphogan.com/learn/pdf/tableless\_contact\_form.pdf](http://www.bphogan.com/learn/pdf/tableless_contact_form.pdf)
> 
> I ran into a problem that I can’t solve.
> 
> When I click on Submit I get the following error:
> 
> NoMethodError in #
> 
> undefined method `const\_available?’ for FrontController:Class
> 
> RAILS\_ROOT: ./script/…/config/…  
> Application Trace | Framework Trace | Full Trace
> 
> Request
> 
> Parameters: {“commit”=\>“Send”, “contact”=\>{“name”=\>“”, “message”=\>“”,  
> “subject”=\>“”, “email\_address”=\>“”}}
> 
> Any ideas on what its looking for. My code looks exactly like Brian’s

Contact View:  
\<%=error\_messages\_for “contact” %\>  
\<%= start\_form\_tag :controller=\>“front\_controller”,  
:action=\>“send\_contact\_request” %\>

| Name |
| \<%= text\_field("contact", "name") %\> |
| Email |
| \<%= text\_field("contact", "email\_address") %\> |
| Subject |
| \<%= text\_field("contact", "subject") %\> |
| Message |
| \<%= text\_area("contact", "message") %\> |

\<%= submit\_tag "Send" %\> \<%= end\_form\_tag %\>

Conrtoller:  
def contact  
@contact = Contact.new  
end

def send\_contact\_request  
breakpoint  
@contact = Contact.new(params[‘contact’])  
if @contact.save  
begin  
Mailer::deliver\_contact\_message(@contact)  
flash[:notice] = “Success!”  
redirect\_to :action=\> “contact”  
rescue  
flash[:notice] = “It broke!”  
render :action=\> “contact”  
end  
else  
render :action=\> “contact”  
end  
end
