Joomla: Setup Smtp Email Capability Using a Gmail Account

This is to setup email capability in a Joomla project. You can use a Gmail account to act as the smtp server.

Set smtp server settings

In Joomla admin panel go to Site -> Global Configuration -> Server -> Mail Settings and set these parameters:


Mailer - SMTP Server
SMTP - Yes
SMTP Security - SSL
Port - 465 or 587
SMTP Username - your gmail email address
SMTP password - your gmail password
SMTP host: smtp.gmail.com

You now have access to a smtp server to send emails from Joomla.

Sending an email

You can use the following to send a basic email. Will generate a error message if not sent successfully.


jimport(‘joomla.mail.helper’);

//clean functions eliminate risk of script injection 
//attacks from a form submit.
$sender_name = JMailHelper::cleanAddress($sender_name);
$subject = JMailHelper::cleanSubject($subject);
$body = JMailHelper::cleanBody($body)
$mode = true; //true=html, false=plain text
$cc = 'some@mail.com'; //cc setting might not work. Try the bcc instead.
$bcc[] = 'another@mail.com'; //Is an array of addresses

if (!JUtility::sendMail($sender_email, $sender_name, $recipient,
 $subject, $body, $mode, $cc, $bcc))
{
	JError::raiseNotice( 500, 'Email failed.' );
 }


The 6th parameter $msgType sets if email body is plain text or html. Default is plain text. If your sending html then set it to true.

Sending attachments


$attach[] = "/path/to/file";
$attach[] = "/path/to/file";
.
.
.
JUtility::sendMail($sender_email, $sender_name, $recipient, 
$subject, $body,false,'','',$attach);

Take a look at the sendMail() API doc here.

Leave a comment

10 Comments.

  1. Robert Wilson

    thanks for the post

  2. Does not work, has someone made it work?

  3. It works!!! Thanks a lot :mrgreen:

  4. thankyou it works :)

  5. The following from address failed:
    Error: Mail has not been sent. Please try again later.

    I have set it up as you guys mentioned .If you have any solution pls mail me my mail is rpv19852000@gmail.com …thanks in advance :oops:

  6. Hi There ,
    I Do All config that mentioned on this post
    and actived gmail authentication,
    I do’nt know why it doesn’t work!!!! :sad: :sad: :sad: :sad:

  7. Hi My dear friend

    I’m working in joomla 2.5.X and tested it in joomla 1.5.
    I face this error message “Could not Coneccft to Smtp host!”
    I have tested all config with phpmailer and swiftmailer
    thus, I faced this popular problem on there :
    “Could not Coneccft to Smtp host!”

    It “worthy to say” I trying send email with gmail smtp remote server
    “IT DID WORKED”
    and Now Dosen’t Work!

    What I DO?

    yours sincerly

  8. The following from address failed: avlshop.com@gmail.com
    Registration failed: An error was encountered while sending the registration email. A message has been sent to the administrator of this site.
    please tell me why ???