While working on a Joomla website recently I had the annoying problem of a contact form failing to send. It took longer than I would have like to spend looking for the solution so hopefully you will find this article before spending the time I did trying to get to the bottom of it. As usual, in hindsight its actually quite simple.
Looking in my mail servers logs I could see why the email was failing to send. For some reason the from address of the email was set to
@adminemail@. Naturally the receiving mail server was rejecting it based on the fact that it couldn’t do an SPF check on this non-address.
Why oh why was I being cursed with this problem? Well I never did totally get to the bottom of it but I did figure out the broad strokes. My web server is a Windows based one running Plesk 10. Originally this version of Plesk didn't have PHP 5.3 support so they released an addon to install it.
The other part of this mystery is if you recognise
@adminemail@from somewhere you have probably leafed through php.ini recently and seen this:
; For Win32 only. ; http://php.net/sendmail-from ;sendmail_from = email@example.com sendmail_from = @adminemail@
It is the default admin email address that
mail() uses. You’re suppose to set it to your admin from address. Trouble is, the server doesn’t just host one site though so I can’t set it manually in the php.ini.
Now what I assume was supposed to happen was that Plesk should insert a sane value into this so that every client doesn’t have this problem. For whatever reason, it doesn’t.
Normally this isn’t a problem, if you’ve written form processing code before you’ve probably done something like this to cut down on the likelihood that your precious cargo is going to be flagged as spam:
ini_set('sendmail_from',$fromaddress); $mail_sent = mail($to, $subject, $msg, $headers, "-f" . $fromaddress); ini_restore('sendmail_from');
However when you’re detailing with a CMS like WordPress or Joomla or some such you find yourself restricted by what would be simple issues but are obfuscated by the layers of the system that build this up. Plus if you go editing the core you will have to remember to re-apply these modifications every time you update.
We are agreed then that this isn't the best solution all round. Is there a better option? Well you don’t think I would have dragged you through these last 8 paragraphs if I didn't have something up my sleeve do you?
The solution is to turn back to Plesk and explicitly tell it to set the from address, like so:
- Log in to Plesk
- In the top right hand corner click in the search box and type the first few characters of your domain. This is such a handy feature. I’ve been using Plesk for almost a decade now and I don’t know why but it was only in the last 6 months that I realised how handy this is. So fast! Anyway select the offending domain.
- Click the
Websites & Domainstab
- Click the name of the domain in the table at the bottom of the page
- Click the
- Scroll to the bottom of the page and find your
Additional configuration directivestextarea:
- Enter this snippet in to it:
sendmail_from = firstname.lastname@example.org
This is a programming website, I don’t have to say replace
email@example.com your desired email address – do I?
OKto save this information.
Hopefully you will now test your form again and see your inbox light up with a delivered form email!