ruby on rails - Send thank you message with mail_form -


i'm using mail_form + simple_form gems send email myself after user submits "contact us" form on site. submit fields database. here working fine.

i'd able send second email user's email address "thank you" message , other copy directly after submission. know message posted flash, email user better in case.

can please provide guidance on how done based on code below? thanks!

model: page.rb

class page < activerecord::base   include mailform::delivery   attribute :name,      :validate => true   attribute :company   attribute :email,     :validate => /\a([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i   attribute :message   attribute :nickname,  :captcha  => true    def headers     {       :subject => "new lead composites first",       :to => "myemail@myemail.com",       :from => "myemail@myemail.com"     }   end end 

controller: pages_controller.rb

class pagescontroller < applicationcontroller   def index   end    def basicform     @page = page.new   end     def create     @page = page.create(page_params)     if @page.save          respond_to |format|         format.html { redirect_to '/' }         format.json { }        end     else       respond_to |format|         format.html { }         format.json { }       end     end     @page.request = request     if @page.deliver     else       flash[:error] = 'cannot send message.'       format.html { redirect_to '/' }     end   end    private     def page_params       params.require(:page).permit(:name, :company, :email, :message)   end end 

you can write after_create callback trigger thank email.

in page model write callback below:

after_create :send_thank_you_email  def send_thank_you_email   email = self.from    mymailer.send_thank_you_email(email).deliver_now end 

now in mymailer write send_thank_you_email action , create mailer view thank mail. hope helps. thanks!


Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -