1

我正在尝试使用 sinatra 中的 Pony Gem 从联系表单(内置 HTML)发送电子邮件,我已按照文档进行操作,但必须缺少某些内容。

这是小马配置

 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>

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

4

1 回答 1

1

你确定你有表单设置来做post吗?如果它似乎正在刷新页面,则form标签可能未正确设置。提交的按钮也应该是inputtype 的标签submit。HTML 需要看起来像这样:

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

   <input type="submit" value="Sign in">
</form>
于 2013-02-05T15:12:29.747 回答