I have built a contact us form and I nicely get the emails in my gApps inbox. However, the received emails show the default :from value of the site. I would like them to appear sent from the email users type in the email field of them form. So, when I hit 'reply' it takes the user address as the address the email has to be sent.
I have tried this, but it does not work. Any idea why?
notifications_mailer.rb
class NotificationsMailer < ActionMailer::Base
default to: "[email protected]"
def new_contact(message)
@message = message
mail(:subject => "[hiKultura.com] #{message.subject}",
:from => message.email)
end
end
ContactController
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
UPDATE
I followed similar cases I found in SO regarding :reply_to and GMail. But, still shows the :to email address when I hit reply. What am I missing???
notifications_mailer.rb
class NotificationsMailer < ActionMailer::Base
default :from => '[email protected]'
def new_contact(message)
@message = message
mail(:reply_to => "[email protected]",
:subject => "[mydomain.com] #{message.subject}",
:to => "[email protected]"
)
end
end