Skip to content

Instantly share code, notes, and snippets.

@t0nylombardi
Last active February 27, 2017 01:04
Show Gist options
  • Save t0nylombardi/e2a7e43b97b52c040733f38f60dd43fd to your computer and use it in GitHub Desktop.
Save t0nylombardi/e2a7e43b97b52c040733f38f60dd43fd to your computer and use it in GitHub Desktop.
Ruby Mailer for newbies
  # app/mailers/support_mailer.rb
  
  #
  # The Main Support Emailer
  #
  class SupportMailer < ApplicationMailer


    # Generic mailer for Support form. Takes hash of params for processing.
    # Hash can includes [:From] and [:Body]
    #
    def support_email(hash = {})
        @input = hash
        @subject = "Support request"
        email =  Rails.env == "development" ? "you@me.com" : "someone@you.com"
        mail_params = {
          to: email,
          from: 'this_person@beats_me.com',
          subject: @subject
        }
        mail(mail_params)
    end
  end
  # app/controllers/yourController.rb
  
  def support_email
    params.each{|p| logger.info "\n\n#{p}\n\n"}
    SupportMailer.support_email(params).deliver_now
    flash[:notice] = "Support Request Sent<br />Thank you for your input"
    redirect_to :root
  end
# config/routes.rb

post 'support_email', to: 'yourController#support_email'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment