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.
thanks for the post
Does not work, has someone made it work?
Do you see the ‘Emailed Failed’ error message when you try to send the email?
Yeah i see..
But I give up the idea, migrated to SMTP
It works!!! Thanks a lot :mrgreen:
thankyou it works :)
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:
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:
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