Contact form 7 is a hugely popular and free WordPress plugin, so you’d think something like this would be built in, but I had the following issue:
There is no way to use functions.php filters or settings in the plugin to stop the HTML email output from adding <p> and <br /> tags into your outgoing emails.
After hours of Googling, I discovered that the popular method of disabling WPCF7_AUTOP in your config.php, doesn’t work for the HTML emails. In fact this one has the WordPress community pretty puzzled, such as in this thread.
I eventually discovered a solution, by editing the plugin files (only way I could find):
In Contact Form 7’s core plugin files, find the file:
wp-content > plugins > contact-form-7 > includes > mail.php
Go to about line # 82 in the file, where you will find:
return wp_mail( $recipient, $subject, $body, $headers, $attachments );
Immediately above that line, add in a new line:
$body = str_replace(‘<p>’, ”, $body);
$body = str_replace(‘</p>’, ”, $body);
$body = str_replace(‘<br />’, ”, $body);
only problem is that it will remove all of these tags, even if you placed them manually in your email templates.
So, to fix that, just add a special class to your tags in your lovely email template. Example: <p class=”myclass”> <br class=”myclass” />. This will prevent the above solution from ruining your template & content.