如何使用Pony向Sinatra发送邮件?

时间:2015-11-06 01:10:42

标签: ruby forms email sinatra pony

我无法使用我在Sinatra中构建的联系表单发送电子邮件。我正在使用Pony宝石。出于某种原因,我收到此错误说“没有这样的文件存在 - 哪个sendmail'。我已经安装了' sendmail'我仍然有同样的问题。我对任何建议持开放态度。代码如下:

联系表格

<form action='/' id='contact' name='contact' method='post' novalidate='novalidate' >

                    <div class="form-group">

                        <div class="input-wrap">
                        <input type="text" class='form-control' name='name' id='name' placeholder='NAME'>
                        </div>

                        <br>

                    <div class="input-wrap">
                        <input type="email" class='form-control' name='mail' id='mail' placeholder='EMAIL'>
                    </div>

                    <br>

                    <div class="input-wrap">
                        <input type="text" class='form-control' name='subject' id='subject' placeholder='SUBJECT'>

                    </div>

                    <br>
                    <div class="input-wrap">
                        <textarea placeholder='MESSAGE' class='form-control' name="body" id="body" cols="30" rows="10"></textarea>
                    </div>
                    <br>

                    <input type='submit' value='SEND' id='button'>
                    </div>
                </form>

main.rb的

require 'rubygems'
require 'sinatra'
require 'bundler/setup'



get '/' do 
File.read('index.html')
end

post '/' do
require 'pony'
name  = params[:name]
mail = params[:mail]
subject = params[:subject]
body  = params[:body]


Pony.mail(:to => 'mjstokes1986@att.net', :from => '#{name}', :subject => '#{subject}', :body => '#{body}')

# File.read('index.html')

redirect '/success'

end

get '/success' do
File.read('success.html')
end

1 个答案:

答案 0 :(得分:0)

尝试告诉Pony.mail方法找到sendmail的位置。您可以使用which sendmail找到您的sendmail位置。 (如果这没有返回任何内容,那么你还没有正确安装sendmail。)

Pony.mail({
  ...
  :via_options => { :location  => '/path/to/your/sendmail'}
})