• Skip to main content
  • Skip to primary sidebar

Victor Font Consulting Group, LLC

The DEX Intranet Specialists

  • Home
  • Care Plans
    • Care Articles
    • Optional Subscriptions
  • Consultations
  • Products
    • Code Snippets
    • Public GitHub Repositories
    • Gist Snippets
    • Pastebin Snippets (Free)
    • Free Plugins
  • FAQs
  • Support
    • Graphic Design
  • Contact
    • Speakers
    • Portfolio
  • Resources
    • Free WordPress Video Training
    • Tutorials
    • Articles
    • Cybersecurity
    • EU Referral Network

Customize Formidable Forms Email Mime Type

June 23, 2017 By Victor M. Font Jr.

On the Formidable Forms Community Support Forum, a customer asks,

How do I change the mime type of an email to text/x-gm-impdata so the content can be imported into Goldmine?

Formidable uses the WordPress wp_mail() function to send emails. Unless otherwise specified, the wp_mail function defaults the content type (mime) of any email to text/plain. The function provides a filter that allows you change the content type. The filter is wp_mail_content_type. To change the mime type for all emails, you would use:

Unfortunately, I've tested this and it doesn't work with Formidable. Instead of using the WordPress supplied filter, Formidable hard codes the mime type as 'text/plain' or 'text/html'. Formidable also has an undocumented filter called frm_email_header that we can use to manipulate the content or mime type. If we examine the output of this filter, just prior to Formidable's call to wp_mail, the header contains a three element array that has the following content (as viewed with the Kint debugger):

The value of the third element will either be Content-Type: text/html; charset="UTF-8" or Content-Type: text/plain; charset="UTF-8". Knowing this, we can change the mime type prior to the send action. Since this is a simple array, the way to do this is to remove the third element and replace it with the new content type. The code looks like this:

This works perfectly, but it changes the mime type for all emails sent by Formidable. So this needs to be wrapped in code that limits it to the specific form. This also may not work at all if you are using a 3rd party SMTP server such as Mandrill or Sparkpost. When I was testing this code in my local environment, I had Sparkpost enabled and Sparkpost kept changing the content type back to text/html. My recommendation is not to use any 3rd party SMTP sender with this process.

The last step is to wrap the apply frm_email_header filter in a formidable hook that fires after submit but before the email is sent. For this we can use the frm_pre_create_entry hook.

Note that I use form_key instead of form_id. When you migrate a Formidable form to a different environment using export/import, the form id will change. The form key remains static. Using form key will save you a headache tracking down why your code doesn't work after moving to a different environment. Just remember to change the form_key in your code from 'contact2' to the key of your form.

If this all works for you, viewing the email source code will display a header similar to this one:

  • 12shares
  • Facebook6
  • Twitter0
  • Pinterest2
  • LinkedIn2
  • Print
  • SMS0

Filed Under: Computers and Internet, Formidable Forms, Tutorial, WordPress Tagged With: Computers and Internet, Formidable Forms, Tutorial, WordPress

About Victor M. Font Jr.

Victor M. Font Jr. is an award winning author, entrepreneur, and Senior IT Executive. A Founding Board Member of the North Carolina Executive Roundtable, he has served on the Board of Advisors, of the North Carolina Technology Association, the International Institute of Business Analysis, Association of Information Technology Professionals, Toastmasters International, and the North Carolina Commission for Mental Health, Developmental Disabilities, and Substance Abuse Services. He is author of several books including The Ultimate Guide to the SDLC and Winning With WordPress Basics, and Cybersecurity.

Primary Sidebar

Shopping Cart

Books

  • Ultimate Guide to the SDLC front cover The Ultimate Guide to the SDLC
    Rated 5.00 out of 5
    $74.95
  • Winning With WordPress Basics 2nd Edition Winning With WordPress Basics 2nd Edition $19.95

Recent Articles

  • Modern Scam Defense: How Consumers and Businesses Can Recognize and Stop Email, Phone, and Text Fraud
  • How to Write a PRD So Dense It’s Technically a Novel
  • Top 5 Plugin Names That Scare Our Legal Department
  • When Agile Meets Our 3-Year Waterfall Roadmap: A Love Story
  • Why Our Enterprise Needs 27 Stakeholders to Approve a Button Color Change

Top 10 Article Categories

Best Practice Code Snippet Computers and Internet Genesis How To Leadership Programming Servant Leadership Tutorial WordPress

 
We only use analytical cookies on our website that allow us to recognize and count the number of visitors, but they do not identify you individually. They help us to improve the way our website works. By clicking Accept you, agree to cookies being used in accordance with our Cookie Policy.