Thursday, June 4, 2009

Sending mail through ruby on rails

I was working for site and needed something like this for contact form.
is really nice tutorial for sending mails , can be used for static sites. This helped me a lot.

But faced some problems,
I didn't get subject and message although the mail was going to the right address.
It was merging with the message and passing through the recipients only .
No other field required for that

so I made some changes in that

in (model) ContactMailer.rd
def contact(recipient, subject, message)
  @subject = "message:: "+subject 
  @message = message
  @recipients = '' 
  @sent_on =
  @from = recipient
and in ContactController.rb
def sendmail
  email = params[:email]
  subject = email[:subject]
  recipient = email[:recipient]
  message = email[:message]
  ContactMailer.deliver_contact(recipient, subject, message)
  return if request.xhr?
  render :text => 'Message sent successfully'

No comments:

Post a Comment