Skip to content

Instantly share code, notes, and snippets.

@DylanFM
Created March 21, 2009 04:16
Show Gist options
  • Select an option

  • Save DylanFM/82724 to your computer and use it in GitHub Desktop.

Select an option

Save DylanFM/82724 to your computer and use it in GitHub Desktop.
#Mailer's controller method
def contact
if request.post?
@contact = Contact.new(params[:contact])
if @contact.valid?
send_mail(ContactMailer, :notify, {
:from => @contact.email,
:to => 'email',
:subject => "New enquiry from website"
}, { :contact => @contact })
render "Thankyou, your message has been sent."
else
render :contact
end
else
@contact = Contact.new
render
end
end
#Config enviro development.rb
Merb::BootLoader.after_app_loads do
# This will get executed after your app's classes have been loaded.
Merb::Mailer.config = {
:host => 'host',
:port => '25',
:user => 'user',
:pass => 'pass',
:auth => :plain,
:domain => 'domain'
}
end
#Contact mailer
class ContactMailer < Merb::MailController
def notify
@contact = params[:contact]
render_mail
end
end
#Contact model
class Contact
include DataMapper::Resource
property :id, Serial
property :name, String, :nullable => false
property :email, String, :nullable => false
property :message, String, :nullable => false
validates_format :email, :as => :email_address
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment