用Pony和Sinatra发送邮件 [英] Sending mail with Pony and Sinatra
问题描述
我正在尝试从一个联系表格(内置的HTML)发送一封电子邮件,与小马宝石在sinatra内,我遵循了文件,但有些东西必须丢失。
这是Pony配置
get'/ contact'do
erb:contact,:layout => :布局
结束
post'/ contact'do
需要'pony'
Pony.mail({
:from => params [:名称],
:to =>'myemailaddress',
:subject => params [:name] +已通过网站与您联系,
:body => params [:comment],
:via =>:smtp,
:via_options => {
:address =>'smtp.gmail.com',
:port =''587',
:enable_starttls_auto => true,
:user_name =>'myemailaddress',
:password =>'mypassword',
: =>:plain,
:domain =>localhost.localdomain
}
})
redirect'/ success'
end
get('/ success')do
@notification =谢谢你的电子邮件,我会很快联系。
erb:index,:layout => :layout
end
所以点击提交后,联系人页面被重新呈现,没有消息
这是我的提交按钮
< button type =submit class =btnvalue =send> Submit< / button>
我在这里是否缺少触发器?
表单
标记。此外,提交的按钮应该是输入
标签,类型为 submit
。 HTML需要看起来像这样: < form action =/ contactmethod =post>
<! - 你的表单元素到这里 - >
< input type =submitvalue =登录>
< / form>
I am trying to send an email from a contact form (built in HTML) with the Pony Gem within sinatra, I have followed the docs but something must be missing.
This is the Pony config
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
So after clicking submit the contact page gets re rendered with no message
here is my submit button
<button type="submit" class="btn" value="send">Submit</button>
Am i missing a trigger here somewhere?
Are you sure you have the form setup to do a post
? If it seems to be refreshing the page the form
tag may not be setup properly. Also the button to submit should be an input
tag of type submit
. The HTML would need to look something like this:
<form action="/contact" method="post">
<!-- your form elements go here -->
<input type="submit" value="Sign in">
</form>
这篇关于用Pony和Sinatra发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!