与Pony和Sinatra一起发送邮件

时间:2013-02-05 14:08:39

标签: ruby forms email sinatra pony

我正在尝试从sinatra中的Pony Gem发送一封联系表格(内置HTML)中的电子邮件,我已经按照文档进行了操作,但必须遗漏一些内容。

这是Pony配置

 get '/contact' do
  erb :contact, :layout => :layout
 end

 post '/contact' do
 require 'pony'
 Pony.mail({
:from => params[:name],
    :to => 'myemailaddress',
    :subject => params[:name] + "has contacted you via the Website",
    :body => params[:comment],
    :via => :smtp,
    :via_options => {
     :address              => 'smtp.gmail.com',
     :port                 => '587',
     :enable_starttls_auto => true,
     :user_name            => 'myemailaddress',
     :password             => 'mypassword',
     :authentication       => :plain, 
     :domain               => "localhost.localdomain" 
     }
    })
    redirect '/success' 
   end


   get('/success') do
@notification = "Thanks for your email. I'll be in touch soon."
erb :index, :layout => :layout
   end

因此,点击提交后,联系页面将重新呈现,不显示任何消息

这是我的提交按钮

 <button type="submit" class="btn" value="send">Submit</button>

我在某处错过了触发器吗?

1 个答案:

答案 0 :(得分:1)

您确定要使用表单设置post吗?如果它似乎刷新了页面,form标记可能无法正确设置。此外,要提交的按钮应为input类型submit的标记。 HTML需要看起来像这样:

<form action="/contact" method="post">
   <!-- your form elements go here -->

   <input type="submit" value="Sign in">
</form>