お問い合わせフォームを作成しましたが、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