5

お問い合わせフォームを作成しましたが、gApps の受信トレイにメールが届きます。ただし、受信した電子メールには、サイトのデフォルトの :from 値が表示されます。ユーザーがフォームの電子メール フィールドに入力した電子メールから送信されたように見せたいと思います。そのため、「返信」を押すと、メールを送信する必要があるアドレスとしてユーザーアドレスが使用されます。

私はこれを試しましたが、うまくいきません。理由はありますか?

notifications_mailer.rb

class NotificationsMailer < ActionMailer::Base
  default to: "info@hikultura.com"

  def new_contact(message)
      @message = message
      mail(:subject => "[hiKultura.com] #{message.subject}",
        :from => message.email)
  end
end

連絡先コントローラー

class ContactController < ApplicationController

  def new
    @message = Contactmessage.new
  end

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

    if @message.valid?
      NotificationsMailer.new_contact(@message).deliver
      redirect_to(root_path, :notice => "Message was successfully sent.")
    else
      flash.now.alert = "Please fill all fields."
      render :new
    end
  end

end

アップデート

:reply_to と GMail に関して SO で見つけた同様のケースに従いました。しかし、返信を押すと、まだ :to メールアドレスが表示されます。私は何が欠けていますか???

notifications_mailer.rb

class NotificationsMailer < ActionMailer::Base

   default :from => 'no-reply@mydomain.com'

  def new_contact(message)
      @message = message
      mail(:reply_to => "mierda@hotmail.com",
      :subject => "[mydomain.com] #{message.subject}", 
      :to => "admin@mydomain.com"
      )
  end
end
4

1 に答える 1

5

ほとんどの SMTP プロバイダー (Gmail など) では、SMTP サーバーにログインしているアカウントに関連付けられているアドレス以外のアドレスからメールを送信することはできません。あなたのアプリで。考えてみれば、それはセキュリティ/スパム保護にとって非常に理にかなっています。あなたの電子メール アドレスを差出人アドレスとして示した電子メールを誰でも送信できるようにしたいですか? 私は確かにしないでしょう。別の方法は、:reply_to を使用することです。メール プログラムで返信をクリックすると、存在する場合はこれを使用する必要があります。

  mail(:subject => "[hiKultura.com] #{message.subject}",
    :reply_to => message.email)
于 2013-03-19T20:08:18.330 に答える