Fixing email settings in Joomla – SMTP and Sendmail

Had a problem with a server that wasn't sending mail. There didn't seem to be any way to debug the Mail system. I was sending mail using Chronoforms and added a debugger, but it said the mail was sending correctly.

After quite a bit of investigation, here are my findings and fixes.

First of all, Chronoforms wasn't sending email, to fix that, edit administrator\components\com_chronoforms\form_actions\email\email.php, scroll to line 216 and replace :

$JMail = new JMail();

with

//$JMail = new JMail();
$JMail = JFactory::getMailer();

thanks to http://blog.kleeng.com/?tag=/joomla for that one!

It turned out the web server had a full mail queue, so I decided to switch to SMTP email and used my own mail server, which worked correctly. A few days later the server mail queue was cleared and the client didn't want to use my mail server, so I switched it back to Sendmail.

I did, BUT it still wasn't sending! which was very confusing, because I even tried sending email directly using /usr/sbin/sendmail from the command line and this worked perfectly. Eventually I discovered that Joomla sends e-mail via /library/phpmailer/phpmail.php

I added a bit of debug code to that and found the problem. It was that Joomla was attempting to use sendmail using the "-f" flag which attempts to send mail using a specific address, rather than letting sendmail do that itself. The extra -f flag headers were causing Gmail to detect spam and bounce. I found messages in my spam folder saying :

host gmail-smtp-in.l.google.com[173.194.66.26] said:
    550-5.7.1 [109.104.88.55      12] Our system has detected that this message
    is 550-5.7.1 likely unsolicited mail. To reduce the amount of spam sent to
    Gmail, 550-5.7.1 this message has been blocked.

Therefore the actual fix turned out pretty easy, edit /library/phpmailer/phpmail.php and remove the -f flag.

Line 875 :

protected function SendmailSend($header, $body) {
if ($this->Sender != '') {
      $sendmail = sprintf("%s -oi -f%s -t", escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));
      // Add this line to replace the one above
      $sendmail = sprintf("%s -oi -t", escapeshellcmd($this->Sendmail), escapeshellarg($this->Sender));

      } else {

Fixed!

Once that was done I decided to try Gmail again and it worked, the correct settings are:

SMTP Authentication: Yes

SMTP Security: SSL

SMTP Port: 465

SMTP Username: your_username@gmail.com

SMTP password: your_password

SMTP Host: smtp.gmail.com

Only took 5 days to figure that one out! 🙂

Leave a Reply