Skip to content

Instantly share code, notes, and snippets.

@pmichaeljones
Last active August 29, 2015 14:13
Show Gist options
  • Save pmichaeljones/949e7ac9af7ff62ff265 to your computer and use it in GitHub Desktop.
Save pmichaeljones/949e7ac9af7ff62ff265 to your computer and use it in GitHub Desktop.
Sending Mandrill Merge Variables from a Rails Controller
class ContactMailer < ActionMailer::Base
def contact_form_email(obj)
mail :subject => "Contact Form Submission",
:to => "pmichaeljones@gmail.com",
:from => "#{obj[:user][:address]}"
#THIS IS THE IMPORTANT CHANGE
merge_vars =
{
"name" => "Patty Jones",
"message" => "What up sir?"
}
#DON'T FORGET TO FORMAT IT AS A JSON OBJECT BEFORE SENDING
headers['X-MC-MergeVars'] = merge_vars.to_json
headers['X-MC-Template'] = "Contact Email Confirmation"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment