Archive for November, 2008

Use Google Apps & Gmail To Send SMTP Mails In Joomla

Wednesday, November 19th, 2008

I am sure every body using Joomla with Google Apps or Gmail will be facing problem to authenticate SMTP in Global configuration. To use Google Apps or Gmail as SMTP mail sender you should first enable SSL on your server. Next, you need to hack the phpmailer page to connect with Google SMTP mail server to send mails.This phpmailer page differs in which version of joomla you are using. Below is the location of the phpmailer page which you need to hack. Before doing anything be smart to backup the file.

Joomla 1.0.x: includes/class.phpmailer.php

Joomla 1.5: includes/phpmailer.php

Find the code around the line 537:

if(strstr($hosts[$index], ":"))
        list($host, $port) = explode(":", $hosts[$index]);
else
{
        $host = $hosts[$index];
        $port = $this->Port;
}

Replace it with:

if (preg_match('#(([a-z]+://)?[^:]+):(\d+)#i', $hosts[$index], $match))
{
        $host = $match[1];
        $port = $match[3];
}
else
{
        $host = $hosts[$index];
        $port = $this->Port;
}

Now login to your joomla backend and go to Mailer in Global configuration

Enter/choose the options in below format

Mailer: SMTP Server
Mail From: <your_user_id>@gmail.com (Google apps user: your_user_id@yourdomain.com)
SMTP Auth: Yes
SMTP User: <your_user_id>@gmail.com (Google apps user: your_user_id@yourdomain.com)
SMTP Password: <your_password>
SMTP Host: ssl://smtp.gmail.com:465

Be sure that you have enable POP in your Gmail or Google Apps before you save this and test. All the best.