0

簡単な連絡先フォームを作成しました( http://matharvard.ca/posts/2011/aug/22/contact-form-in-rails-3/に似ています)。私の開発では、(レターオープナーを使用して)正常に動作しますが、私の制作では、メールを送信しません。いくつかの解決策を検索しましたが、解決策が見つかりませんでした。to:が で定義されているにもかかわらず、なぜ電子メールを送信しないのmodels/mailers/contact_mailer.rbですか? Heroku のログでは、パラメータは問題ないように見えましたが、見つかりませんでしたto:... 助けてください。

レポ全体 https://github.com/yhagio/yhagio

実際のお問い合わせフォーム http://yhagio.herokuapp.com/contact

config/environments/production.rb

config.action_mailer.default_url_options = { :host => "yhagio.herokuapp.com" }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
  :address              => "smtp.gmail.com",
  :domain               => 'yhagio.herokuapp.com',
  :port                 => 587,
  :user_name            => ENV['GMAIL_USERNAME'],
  :password             => ENV['GMAIL_PASSWORD'],
  :authentication       => :plain,
  :enable_starttls_auto => true,
}

モデル/メーラー/contact_mailer.rb

class ContactMailer < ActionMailer::Base
  default to: ENV['MYGMAIL']

  def contact_message(message)
    @message = message
    mail from: message.email, subject: message.subject
  end
end

メッセージ.rb

class Message
  include ActiveModel::Validations
  include ActiveModel::Conversion
  extend ActiveModel::Naming

  validates_presence_of :subject, :body, :name
  validates :email,  presence: true, format: { with: /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i  }

  attr_accessor :name, :email, :body, :subject

  def initialize(attributes = {})
    attributes.each do |name, value|
      send("#{name}=", value)
    end
  end

  def persisted?
    false
  end
end

contact_mailer.rb

class ContactController < ApplicationController

  def new
    @message = Message.new
  end

  def create
    @message = Message.new(params[:message])

    if @message.valid?
      ContactMailer.contact_message(@message).deliver
      redirect_to root_path
      flash[:success] = "Message was successfully sent."
    else
      flash[:error] = "Please fill all fields."
      render :new
    end
  end
end

ヒロクのログ

app[web.1]: Started POST "/contact" for 173.176.46.53 at 2013-07-22 23:14:50 +0000
Parameters: {"utf8"=>"✓", "authenticity_token"=>"czYfbExDwXdHvzKP7fa3LMV50CbucTGwxwV/sZ22E/c=", "message"=>{"name"=>"test", "email"=>"test@test.com", "subject"=>"hello", "body"=>"https://github.com/yhagio/yhagio/commit/c8a09d769df43a58f82959fc1e72e3c88b79821d"}, "commit"=>"Send"}
Processing by ContactController#create as HTML
Rendered contact_mailer/contact_message.html.haml (2.4ms)
at=info method=POST path=/contact host=yhagio.herokuapp.com fwd="173.176.46.53" dyno=web.1 connect=8ms service=76ms status=500 bytes=643
Sent mail to  (10ms)
Completed 500 Internal Server Error in 31ms
app/controllers/contact_controller.rb:11:in `create'
ArgumentError (At least one recipient (To, Cc or Bcc) is required to send a message):

更新: 7 月 24 日

config/environments/production.rbで変更した Mailgun を試しました

config.action_mailer.smtp_settings = {
  :address        => 'smtp.mailgun.org',
  :domain         => 'yhagio.herokuapp.com',
  :port           => 587, 
  :user_name      => ENV['MAILGUN_SMTP_LOGIN'],
  :password       => ENV['MAILGUN_SMTP_PASSWORD'],
  :authentication => :plain,
  :enable_starttls_auto => true,
}
4

1 に答える 1

0

ドメインは yhagio.herokuapp.com ではなく gmail.com にすべきだと思います。

于 2013-07-23T16:15:49.663 に答える