类似的问题 Rails 联系表格不起作用
指南:https ://github.com/thomasklemm/email_form_rails rails 3.2.x
应用\模型\消息.rb
class Message
include ActiveAttr::Model
include ActiveModel::Validations
attribute :name
attribute :email
attribute :subject
attribute :body
attr_accessible :name, :email, :subject, :body
validates_presence_of :name
validates_presence_of :email
validates :email, email_format: { message: "is not looking like a valid email address"}
validates_presence_of :subject
validates_length_of :body, maximum: 500
end
app\mailers\contact_form.rb
class ContactForm < ActionMailer::Base
default from: "myemail@gmail.com"
default to: "myemail@gmail.com"
def email_form(message)
@message = message
mail subject: "#{message.subject} #{message.name}"
mail body: "#{message.body}"
end
end
发展.rb
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => "mydomain.com",
:user_name => "myemail@gmail.com",
:password => "mypassword",
:authentication => :plain,
:enable_starttls_auto => true
}
config.action_mailer.default_url_options = {
:host => "localhost:3000"
}
命令输出
在 2012-09-04 22:10:40 +0700 开始 POST "/email" for 127.0.0.1 由 HomeController#send_email_form 作为 HTML 参数处理:{"utf8"=>"√", "authenticity_token"=>"w39BLqCrjTMm4RRi/ Sm5hZoEpcw46 npyRy/RS0h48x0=", "message"=>{"name"=>"anonymousxxx", "email"=>"anonymousxxx@yahoo.com", "subject"=>"Test", "body"=>" send email"}, "commit"=>"Create Message"} Redirected to localhost:3000/home/contact Completed 302 Found in 1ms (ActiveRecord: 0.0ms)
但是电子邮件(消息)没有收到我的电子邮件,..