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:

Leave a Reply