Contact form in ruby, sinatra, and haml

前端 未结 5 1000
天命终不由人
天命终不由人 2021-01-30 09:15

I\'m new to all three, and I\'m trying to write a simple contact form for a website. The code I have come up with is below, but I know there are some fundamental problems with

5条回答
  •  情深已故
    2021-01-30 09:54

    In case anyone can use this, here is what you might need to use your gmail account to send mail.

    post '/contact' do 
    require 'pony'
    Pony.mail(
       :name => params[:name],
      :mail => params[:mail],
      :body => params[:body],
      :to => 'a_lumbee@gmail.com',
      :subject => params[:name] + " has contacted you",
      :body => params[:message],
      :port => '587',
      :via => :smtp,
      :via_options => { 
        :address              => 'smtp.gmail.com', 
        :port                 => '587', 
        :enable_starttls_auto => true, 
        :user_name            => 'lumbee', 
        :password             => 'p@55w0rd', 
        :authentication       => :plain, 
        :domain               => 'localhost.localdomain'
      })
    redirect '/success' 
    end
    

    Note the redirect at the end, so you will need a success.haml to indicate to the user that their email was sent successfully.

提交回复
热议问题