表单数据未在电子邮件中发送

时间:2015-05-27 02:44:08

标签: html ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-4

下面是我的代码,我基本上只是模仿。一个专业的网络开发者创建了这个网站,所以我只是按照他们的方式来做。但是,由于某种原因,数据不会在电子邮件中发送。但是,电子邮件会发送。

控制器文件

def createproject
@title = "Create Your Project"
@txtname = params[:txtname]
@txtemail = params[:txtemail]
@txtdates = params[:txtdates]
@tname = params[:tname]
@txtleader = params[:txtleader]
@txttree = params[:txttree]
@txtsolar = params[:txtsolar]
@txtwater = params[:txtwater]
@txtgoats = params[:txtgoats]
@txtkids = params[:txtkids]
@txthouse = params[:txthouse]
@txtroof = params[:txtroof]
@txtlatrine = params[:txtlatrine]
@txtbuild = params[:txtbuild]
if !@txtname.nil? && @txtname != '' 
  @isvalid = true
  @data = {
    :txtname => @txtname,
    :txtemail => @txtemail,
    :txtdates => @txtdates,
    :tname => @tname,
    :txtleader => @txtleader,
    :txttree => @txttree,
    :txtsolar => @txtsolar,
    :txtwater => @txtwater,
    :txtgoats => @txtgoats,
    :txtkids => @txtkids,
    :txthouse => @txthouse,
    :txtroof => @txtroof,
    :txtlatrine => @txtlatrine,
    :txtbuild => @txtbuild
  }
end
if @isvalid
  ContactUsMailer.createproject_mail(@data).deliver
  respond_to do |format|
    format.html {render :layout=>"homeLayout"}
  end
else
  respond_to do |format|
    format.html {render :layout=>"homeLayout"}
  end
end
end

邮件文件

def createproject_mail(data)

@data = data

@txtname = @data[:txtname]
@txtemail = @data[:txtemail]
@txtdates = @data[:txtdates]
@tname = @data[:tname]
@txtleader = @data[:txtleader]
@txttree = @data[:txttree]
@txtsolar = @data[:txtsolar]
@txtwater = @data[:txtwater]
@txtgoats = @data[:txtgoats]
@txtkids = @data[:txtkids]
@txthouse = @data[:txthouse]
@txtroof = @data[:txtroof]
@txtlatrine = @data[:txtlatrine]
@txtbuild = @data[:txtbuild]

mail(:to => "jacob@fusionbible.com", :subject => "TEST", :from => "no-reply@mohhaiti.org")
end

1 个答案:

答案 0 :(得分:1)

将它放在application_helper.rb

def humanize_checkbox(val)
  (val && 'on' == val.downcase) ? 'Yes' : 'No'
end

在邮件程序类中添加此项。   helper :application

并为视图中的复选框调用

<%=humanize_checkbox(@txttree)%>