Being new to WordPress, I had another challenge this week. It appeared that no matter what “name” was entered by the users on a form, the email sent (as a result of the form submission) was always “From : <Blog Name>” instead of “From : <Actual Name of User>“. In fact, all emails (regardless of plugin) would originate “From: <Blog Name>”.
Initially, I assumed the problem was simple in that the form was somehow hard coding the “From” field and it was just a matter of finding the right piece of code within the Contact Form 7 plugin and replacing it.
After 3 hours of the debug-code-test-repeat cycle, I was nowhere closer to solving the problem. I am not a WordPress guru so I was afraid of delving into the WordPress core code. So I started looking through the code for Contact Form 7 plugin. I placed debug statements (PHP error_log) on the interface between Contact Form 7 and the WordPress core code. Specifically, we are talking about the WordPress “wp_mail()” function.
You can specify headers to the “wp_mail()” function, so I verified that Contact Form 7 was sending these correctly. That meant the problem was NOT within Contact Form 7.
One thing within the WP core code confused me: how and what did the filters do? The wp_mail() function was invoking the filters ‘wp_mail_from_name‘ and ‘wp_mail_from’ before calling the core PHP API to transmit the email. Instinctively, my next step was to look for references to any such filters by any plugins. I found quite a few references to this ‘wp_mail_from_name’ filter. While all other plugins seemed to be using the filter only for their exclusive purposes, one plugin, notably JigoShop, was adopting a different route. The call to “add_filter(‘wp_mail_from_name’, ….)” was not matched by a complimentary call to “remove_filter()”.
That means the WordPress core code would always be setting the header field according to the ‘wp_mail_from_name’ function handler set by JigoShop.
Bingo, I had found the problem! Sometimes, you get so excited about finding the problem that you absorb it in all with pleasure. Its an elated feeling to have found out the answer after several hours of debugging.
A couple of days later, I still do not know what is the correct resolution to this problem. I have posted on the JigoShop forum, seeking a solution. So far, it seems a few other folks have encountered the same issue previously.
If I am understanding correctly, JigoShop should only nestle calls to ‘wp_mail()’ between ‘add_filter(‘wp_mail_from_name’…)’ and ‘remove_filter(‘wp_mail_from_name’)’. This way, the JigoShop emails are still sent from the correct “From” field, while still not affecting the rest of the plugins.
Here is my post on the Contact Form 7 plugin forum at WordPress and here is my post on the JigoShop Plugin forum at WordPress. Last, here is my post on the official JigoShop forum on the JigoShop.com site.
Update 02 August 2013
I just heard back from one of the development team members at JigoShop. The good news is that they did acknowledge the conflict. More good news is that the fix is simple, just as I had proposed above i.e. to have ‘add_filter()’ and ‘remove_filter()’ around each call to ‘wp_mail()’.
The official fix will be included in the next JigoShop release.
If you were waiting for bad news, sorry to disappoint you…there is none!