我正在尝试在Rails 5中构建一个联系表单,其中表单将名称,电子邮件和正文添加到我的Gmail中。点击"提交",此表单发送到我的Gmail,但是从mygmail到mygmail的gmail消息。
的routes.rb
match '/contact', to: 'me#contact_website', via: 'post'
index.html.erb
<%= form_tag({controller: "me", action: "contact_website"}, method: "post" , class: "form-group") do %>
<%= text_field_tag(:nama, "", placeholder:"Your Name", required: true) %>
<%= email_field_tag(:email, "", placeholder:"Your Email", required: true) %>
<%= text_area_tag(:pesan, "", placeholder:"Your Massage", required: true) %>
<%= submit_tag("Submit") %>
<% end %>
me_controller.rb
def contact_website ()
@nama = params[:nama]
@email = params[:email]
@pesan = params[:pesan]
f @nama.blank? or @email.blank? or @pesan.blank?
@message = "An error occurred while delivering this message."
render action:"index"
else
UserMailMailer.new_message(@nama,@email,@pesan).deliver
@message = "Your messages has been sent."
render action:"index"
#redirect_to root_path, notice: @message
end
user_mail_mailer.rb
class UserMailMailer < ApplicationMailer
default to: 'nugroho.adty@gmail.com'
#layout "new_message"
def new_message (nama,emailnya,pesan)
@nama = nama
@emailnya = emailnya
@pesan = pesan
mail(from: emailnya, subject: 'Contact Request From Website')
#render "new_message"
end
end
new_message.html.erb
<p>Message from <strong><%= @nama %> </strong></p>
<p><%= @pesan %></p>
在new_message.html.erb中,来自表单的电子邮件可以显示但是在user_mail_mailer.rb邮件邮件(来自:emailnya)中没有显示来自联系人的电子邮件