I have recently been working with a client on Godaddy’s Windows hosting, who wanted a WordPress blog transferred over to this hosting. These days, with IIS 7.0 and PHP 5, hosting a WordPress blog on Windows is not a huge problem. Using a standard PHP-based contact form plugin, however, is not so straghtforward.
What’s the problem?
WordPress and (as far as I can tell) all contact form plugins seem to use PHP’s mail() function to send mail through the web. By and large, this is a convenient and configurable solution. However, it seems that on Windows hosting, this function will not work. The only alternative is to use SMTP to send emails.
Thankfully there are two useful plugins and a decent tutorial out there, if you are using Contact Form 7. This tutorial is also useful for those using other contact form plugins who may be running into the same problem.
However, following these tutorials led to a further frustration. Though the test emails from each SMTP plugin’s setup pages sent perfectly, the forms still failed to work. It couldn’t be a hosting setup issue, but had to be a plugin issue.
The person who had worked on the blog originally had installed the wp-contact-form plugin. Having updated this, I was receiving errors relating to sending issues every time I tested the form live. Then I had a thought: the plugins that fix the mail() issue and convert to SMTP do so by telling WordPress how to send the emails. Since WordPress has its own email sending function, it then made sense that forcing the mailing plugins to use this function might make things work again. Furthermore, delving into the SMTP plugins and looking at how they sent their test emails (which by this time I knew were working correctly) showed that they were using WordPress’s send function. This makes sense; the test send has to use the same method or it’s not much of a test!
And that’s where I finally had success. I was working with the wp-contact-form, and I opened up the plugin file (wp-contactform.php) in an editor (you can go to Plugins, find the plugin and click “Edit” too, if you do not have FTP access) and found the line of code that actually sends the email. On 126.96.36.199, this is line 143. The code should read as follows:
mail($recipient, $subject, $fullmsg, $headers);
Ready for some extensive editing? Here goes. Modify this line to use the WordPress mail function instead:
wp_mail($recipient, $subject, $fullmsg, $headers);
That’s it! Hopefully everything should finally be working as expected.
I have not tested this out with Contact Form 7 yet, but if, after using Mario’s tutorials above, you still have no luck, try modifying the plugin in the same way…