Hi there. I’m glad to report that I got this working. It was pretty complicated so bear with me. You’re probably going to want to update your documentation.
First, I wrote a file called testmail.php and manually executed it by running
php testmail.php on the command line of my server. The file looked like this:
<?php mail('email@example.com', 'My Subject', "Line 1\r\nLine 2"); ?>
Then, when I didn’t get anything, I checked /var/mail on my server. I noticed that my www-data user (I’m running Apache on Debian) had unread mail! It was a bunch of undeliverable notices for all the messages I had been trying to send. Each of them had the same error message:
Mailing to remote domains not supported. After Googling that error message, I ran
sudo dpkg-reconfigure exim4-config. Just as I expected, my Exim (the default MTA for Debian) was set to the default setting of
local delivery only; not on a network so I changed it to
internet site; mail is sent and received directly using SMTP and left all the other options as default.
I then ran
php testmail.php again and the email showed up in my inbox right away. I then tried the Newsletter and Contact pages on my website and they worked too! Which is all good news.
The question I have, though, is why do I need a working sendmail on my server? In this case your code for the contact form is clearly not actually connecting to an external SMTP server and sending through there like it’s supposed to, but rather sending directly from my webserver (headers on received messages verify this). Have you tried this on a server without a working MTA and/or checked the headers of received messages to make sure it’s actually sending through the third-party server?