同様の問題 Railsの連絡フォームが機能しない
ガイド:https ://github.com/thomasklemm/email_form_rails rails 3.2.x
app \ models \ message.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
development.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-0422:10:40+0700に127.0.0.1のPOST"/email"を開始しました。HTMLパラメーターとしてのHomeController#send_email_formによる処理:{"utf8" => "√"、 "authenticity_token" => "w39BLqCrjTMm4RRi / Sm5hZoEpcw46 npyRy / RS0h48x0 = "、" message "=> {" name "=>" anonymousxxx "、" email "=>" anonymousxxx@yahoo.com "、" subject "=>" Test "、" body "=>"電子メールの送信"}、" commit"=>"メッセージの作成"}localhost:3000 / home / contactにリダイレクト完了3021ミリ秒で見つかりました(ActiveRecord:0.0ms)
しかし、電子メール(メッセージ)は私の電子メールを受信しません、..