Page 1 of 2

Upgrade of phpmailer library to allow SSL (i.e. GMAIL)

Posted: Thu Aug 21, 2008 10:28 pm
by mannunix
1. Introduction-

Including an upgraded phpmailer library would allow the use of mail services requiring SSL connections (i.e. Google's GMail service).

Optionally it would be of additional benefit to make some minor changes to provide for additional configuration settings to accommodate the use of such services (i.e. SSL/TLS selection, port number selection).

This item seems to be of interest to community members, as the original thread discussing the issue has 9058 views and 95 replies as of the date of this submission, and the resolution is extremely simple and non-impactive.

2. Problem-


It is not currently possible to use an email service that requires SSL authentication (such as GMail) due to the lack of support for SSL in the version of phpmailer (1.7.3) included in Joomla up to v1.5.6.

3. Current workaround-


No workaround currently available. To use Gmail SMTP services you need to apply a "patch" for Joomla from the following thread: http://forum.joomla.org/viewtopic.php?f ... &sk=t&sd=a

4. What is needed-
Update phpmailer library to >=2.0.2 and potentially make small ui modifications(see below) to allow for the additional configuration settings. However, once phpmailer is updated it is possible (but less desirable) to make use of the increased functionality without UI changes if need be.

5. Implementation-
There are two options for implementation:

1. Update the phpmailer library and make modifications to the code/ui to facilitate additional configuration options

2. Update the phpmailer library only, and educate users as to how to configure SSL using the existing code/ui

If only the library is updated, the following configuration settings would allow the use of SSL:

Mailer: SMTP Server
SMTP Authentication: Yes
SMTP Username: <your_user_id>@gmail.com
SMTP Password: <your_password>
SMTP Host: ssl://smtp.gmail.com:465

Both are covered below.

5.1 Code changes-

Updating the phpmailer library itself will only require the replacement of two files in libraries/phpmailer with a one line modifcation in phpmailer.php.

5.1a Current code-
libraries/phpmailer/phpmailer.php
libraries/phpmailer/smtp.php



5.1b Additional code-

Rename the file class.phpmailer.php from the new version of the library to phpmailer.php and place it in libraries/phpmailer.

Rename the file class.smtp.php from the new version of the library to smtp.php and place in libraries/phpmailer.

Modify libraries/phpmailer/phpmailer.php as follows:
- include_once($this->PluginDir . 'class.smtp.php');
+ include_once($this->PluginDir . 'class.smtp.php');

Apply the following changes to add configuration options:
diff -burp joomla.backup/administrator/components/com_config/controllers/application.php joomla.localhost/administrator/components/com_config/controllers/application.php
--- joomla.backup/administrator/components/com_config/controllers/application.php 2008-07-27 01:33:15.000000000 -0400
+++ joomla.localhost/administrator/components/com_config/controllers/application.php 2008-08-21 11:49:35.000000000 -0400
@@ -151,7 +151,9 @@ class ConfigControllerApplication extend

// MAIL SETTINGS
$mailer = array (JHTML::_('select.option', 'mail', JText::_('PHP mail function')), JHTML::_('select.option', 'sendmail', JText::_('Sendmail')), JHTML::_('select.option', 'smtp', JText::_('SMTP Server')));
+ $smtpsecure = array (JHTML::_('select.option', 'none', JText::_('None')), JHTML::_('select.option', 'ssl', 'SSL'), JHTML::_('select.option', 'tls', 'TLS'));
$lists['mailer'] = JHTML::_('select.genericlist', $mailer, 'mailer', 'class="inputbox" size="1"', 'value', 'text', $row->mailer);
+ $lists['smtpsecure'] = JHTML::_('select.genericlist', $smtpsecure, 'smtpsecure', 'class="inputbox" size="1"', 'value', 'text', $row->smtpsecure);
$lists['smtpauth'] = JHTML::_('select.booleanlist', 'smtpauth', 'class="inputbox"', $row->smtpauth);

// CACHE SETTINGS
@@ -331,6 +333,9 @@ class ConfigControllerApplication extend
$config_array['fromname'] = JRequest::getVar('fromname', 'Joomla 1.5', 'post', 'string');
$config_array['sendmail'] = JRequest::getVar('sendmail', '/usr/sbin/sendmail', 'post', 'string');
$config_array['smtpauth'] = JRequest::getVar('smtpauth', 0, 'post', 'int');
+ $config_array['smtpsecure'] = JRequest::getVar('smtpsecure', 'none', 'post', 'word');
+ $smtpport = JRequest::getVar('smtpport', '', 'post', 'int');
+ $config_array['smtpport'] = $smtpport ? $smtpport : '25';
$config_array['smtpuser'] = JRequest::getVar('smtpuser', '', 'post', 'string');
$config_array['smtppass'] = JRequest::getVar('smtppass', '', 'post', 'string', JREQUEST_ALLOWRAW);
$config_array['smtphost'] = JRequest::getVar('smtphost', '', 'post', 'string');
diff -burp joomla.backup/administrator/components/com_config/views/application/tmpl/config_mail.php joomla.localhost/administrator/components/com_config/views/application/tmpl/config_mail.php
--- joomla.backup/administrator/components/com_config/views/application/tmpl/config_mail.php 2008-07-27 01:33:15.000000000 -0400
+++ joomla.localhost/administrator/components/com_config/views/application/tmpl/config_mail.php 2008-08-21 11:52:15.000000000 -0400
@@ -15,6 +15,26 @@
</tr>
<tr>
<td class="key">
+ <span class="editlinktip hasTip" title="<?php echo JText::_( 'SMTP Security' ); ?>::<?php echo JText::_( 'TIPSMTPSECURITY' ); ?>">
+ <?php echo JText::_( 'SMTP Security' ); ?>
+ </span>
+ </td>
+ <td>
+ <?php echo $lists['smtpsecure']; ?>
+ </td>
+ </tr>
+ <tr>
+ <td class="key">
+ <span class="editlinktip hasTip" title="<?php echo JText::_( 'SMTP Port' ); ?>::<?php echo JText::_( 'TIPSMTPPORT' ); ?>">
+ <?php echo JText::_( 'SMTP Port' ); ?>
+ </span>
+ </td>
+ <td>
+ <input class="text_area" type="text" name="smtpport" size="30" value="<?php echo $row->smtpport; ?>" />
+ </td>
+ </tr>
+ <tr>
+ <td class="key">
<span class="editlinktip hasTip" title="<?php echo JText::_( 'Mail From' ); ?>::<?php echo JText::_( 'TIPMAILFROM' ); ?>">
<?php echo JText::_( 'Mail From' ); ?>
</span>
diff -burp joomla.backup/administrator/language/en-GB/en-GB.com_config.ini joomla.localhost/administrator/language/en-GB/en-GB.com_config.ini
--- joomla.backup/administrator/language/en-GB/en-GB.com_config.ini 2008-07-27 01:33:18.000000000 -0400
+++ joomla.localhost/administrator/language/en-GB/en-GB.com_config.ini 2008-08-21 11:55:35.000000000 -0400
@@ -125,7 +125,9 @@ SITE SETTINGS=Site Settings
SMTP AUTH=SMTP Authentication
SMTP HOST=SMTP Host
SMTP PASS=SMTP Password
+SMTP PORT=SMTP Port
SMTP SERVER=SMTP Server
+SMTP SECURITY=SMTP Security
SMTP USER=SMTP Username
STATISTICS=Statistics
SYSTEM=System
@@ -189,6 +191,8 @@ TIPSMTPAUTH=Select Yes if your SMTP Host
TIPSMTPHOST=Enter the name of the SMTP host.
TIPSMTPUSER=Enter the username for access to the SMTP host
TIPSMTPPASS=Enter the password for access to the SMTP host
+TIPSMTPPORT=Enter the port number of your SMTP server. Use 25 for most unsecure servers, and 465 for most secure servers.
+TIPSMTPSECURITY=Select the security model that your SMTP server uses.
TIPTMPFOLDER=Please select a writable Temp folder.
TIPURLSUFFIX=If yes, the system will add a suffix to the URL based on the document type.
TIPUSEMODREWRITE=Select to use the Apache Rewrite Module to catch URLs that meet specific conditions and rewrite them as directed.
diff -burp joomla.backup/libraries/joomla/config.php joomla.localhost/libraries/joomla/config.php
--- joomla.backup/libraries/joomla/config.php 2008-04-23 12:06:38.000000000 -0400
+++ joomla.localhost/libraries/joomla/config.php 2008-08-21 11:57:23.000000000 -0400
@@ -20,6 +20,8 @@ class JFrameworkConfig
var $fromname = '';
var $sendmail = '/usr/sbin/sendmail';
var $smtpauth = '0';
+ var $smtpsecure = 'none';
+ var $smtpport = '25';
var $smtpuser = '';
var $smtppass = '';
var $smtphost = 'localhost';
diff -burp joomla.backup/libraries/joomla/factory.php joomla.localhost/libraries/joomla/factory.php
--- joomla.backup/libraries/joomla/factory.php 2008-07-27 01:33:24.000000000 -0400
+++ joomla.localhost/libraries/joomla/factory.php 2008-08-21 12:00:03.000000000 -0400
@@ -591,6 +591,8 @@ class JFactory
$smtpuser = $conf->getValue('config.smtpuser');
$smtppass = $conf->getValue('config.smtppass');
$smtphost = $conf->getValue('config.smtphost');
+ $smtpsecure = $conf->getValue('config.smtpsecure');
+ $smtpport = $conf->getValue('config.smtpport');
$mailfrom = $conf->getValue('config.mailfrom');
$fromname = $conf->getValue('config.fromname');
$mailer = $conf->getValue('config.mailer');
@@ -605,7 +607,7 @@ class JFactory
switch ($mailer)
{
case 'smtp' :
- $mail->useSMTP($smtpauth, $smtphost, $smtpuser, $smtppass);
+ $mail->useSMTP($smtpauth, $smtphost, $smtpuser, $smtppass, $smtpsecure, $smtpport);
break;
case 'sendmail' :
$mail->IsSendmail();
diff -burp joomla.backup/libraries/joomla/mail/mail.php joomla.localhost/libraries/joomla/mail/mail.php
--- joomla.backup/libraries/joomla/mail/mail.php 2008-07-27 01:33:25.000000000 -0400
+++ joomla.localhost/libraries/joomla/mail/mail.php 2008-08-21 12:02:47.000000000 -0400
@@ -302,12 +302,17 @@ class JMail extends PHPMailer
* @return boolean True on success
* @since 1.5
*/
- function useSMTP($auth = null, $host = null, $user = null, $pass = null)
+ function useSMTP($auth = null, $host = null, $user = null, $pass = null, $secure = null, $port = 25)
{
$this->SMTPAuth = $auth;
$this->Host = $host;
$this->Username = $user;
$this->Password = $pass;
+ $this->Port = $port;
+
+ if ($secure == 'ssl' || $secure == 'tls') {
+ $this->SMTPSecure = $secure;
+ }

if ($this->SMTPAuth !== null && $this->Host !== null && $this->Username !== null && $this->Password !== null) {
$this->IsSMTP();

5.2 User Interface changes-

Here is what we have:
global-config-server-original.png
And here is what we need:
global-config-server-changes.png
6. Compatability-

This fix should pose no issues with backward compatibility since it only augments an existing library and potentially adds two SMTP configuration items.

7. References-

http://forum.joomla.org/viewtopic.php?f ... &sk=t&sd=a

Re: Upgrade of phpmailer library to allow SSL (i.e. GMAIL)

Posted: Wed Sep 17, 2008 5:36 pm
by quiquedcode
Hi
Thanks for the patch, this is what I've been looking for
Did you make some mods or a newer patch for 1.5.7 ? :-[

Re: Upgrade of phpmailer library to allow SSL (i.e. GMAIL)

Posted: Mon Sep 22, 2008 12:59 pm
by dxlwebs
this should be a feature in the joomla core files

Re: Upgrade of phpmailer library to allow SSL (i.e. GMAIL)

Posted: Mon Sep 22, 2008 1:23 pm
by quiquedcode
dxlwebs wrote:this should be a feature in the joomla core files
I Agree 100%. This is a must 8)

Re: Upgrade of phpmailer library to allow SSL (i.e. GMAIL)

Posted: Tue Sep 23, 2008 2:13 am
by MasterScript
I am very tired to fix my smtp. Always error

Re: Upgrade of phpmailer library to allow SSL (i.e. GMAIL)

Posted: Sun Oct 19, 2008 2:13 pm
by MrSilverman
mannunix thanks for this patch. Works fine on my newsportal.

Re: Upgrade of phpmailer library to allow SSL (i.e. GMAIL)

Posted: Fri Oct 24, 2008 11:14 am
by Feldon
I don't see any reason why this shouldn't be in Joomla core WITH the additional configuration settings.

Re: Upgrade of phpmailer library to allow SSL (i.e. GMAIL)

Posted: Fri Nov 07, 2008 3:56 pm
by Yeorwned
Would love to see this in core release!

Re: Upgrade of phpmailer library to allow SSL (i.e. GMAIL)

Posted: Fri Nov 21, 2008 9:12 am
by 9slax
good

Re: Upgrade of phpmailer library to allow SSL (i.e. GMAIL)

Posted: Sat Nov 22, 2008 5:52 am
by joomlacorner
this's patch is base on Joomla 1.5.8 and upgrade phpmailer from Ver 1.73 to . version 2.2
joomla_1.5gmail.patch.zip

Re: Upgrade of phpmailer library to allow SSL (i.e. GMAIL)

Posted: Sat Nov 22, 2008 8:46 am
by willebil
You better post this to the Joomla! tracker, just add an artifact at http://joomlacode.org/gf/project/joomla/tracker/ and attach the patch. The bug squad will then certainly pick it up.

Thanks in advance.

Re: Upgrade of phpmailer library to allow SSL (i.e. GMAIL)

Posted: Sat Nov 22, 2008 11:24 am
by mcsmom

Re: Upgrade of phpmailer library to allow SSL (i.e. GMAIL)

Posted: Wed Dec 17, 2008 12:48 am
by usera
I hope this is implemented. thank you.

Re: Upgrade of phpmailer library to allow SSL (i.e. GMAIL)

Posted: Wed Dec 17, 2008 10:34 am
by saisai
I still have a problem I think i's because I'm still in php4.

:-[

This should be in the core release !

Re: Upgrade of phpmailer library to allow SSL (i.e. GMAIL)

Posted: Sat Dec 20, 2008 11:55 am
by ronaldwillems
Hello joomlacorner,

I'd like to use your patch, but I only have ftp access to my server. So I don't think I can use the .patch format. Could you post a zip with the new versions of all the files included?

Re: Upgrade of phpmailer library to allow SSL (i.e. GMAIL)

Posted: Wed Dec 24, 2008 10:38 am
by jamesp135
thanx for the patch

i agree this needs to be in the standard core files really

Re: Upgrade of phpmailer library to allow SSL (i.e. GMAIL)

Posted: Fri Jan 30, 2009 12:33 am
by henriquerr
I didn't read everything in this forum but I thought this solution more simple and worked with me in Joomla 1.5.8

http://byet.net/showthread.php?t=7142

Re: Upgrade of phpmailer library to allow SSL (i.e. GMAIL)

Posted: Fri Feb 20, 2009 7:26 pm
by tranquang
hi everybody
Thanks mannunix so much for this patch

I've try it, and it don't work with newest version joomla 1.5.9
And I've recode some to solute with this version
You can download my patch at:
http://vinazoom.com/index.php?option=co ... info&id=14

Re: Upgrade of phpmailer library to allow SSL (i.e. GMAIL)

Posted: Sun Mar 01, 2009 5:37 pm
by masqueraderus
Hey tranquang,

Thanks a lot for the patch for 1.5.9. The parameters come onto the admin panel.
But still I am getting the error "SMTP Error! Could not connect to SMTP host."
I am using Joomla on my localhost.
My Mail settings are like this:

Mailer SMTP Server
Mail from myname@gmail.com
From Name websitename
Sendmail Path /usr/sbin/sendmail
SMTP Authentication Yes
SMTP Security (tried both SSL/TSL)
SMTP Port 465
SMTP Username <username>
SMTP Password <password>
SMTP Host (tried smtp.gmail.com, ssl://smtp.gmail.com:465 )

Help, please!

Re: Upgrade of phpmailer library to allow SSL (i.e. GMAIL)

Posted: Sun Mar 01, 2009 5:44 pm
by tranquang
HI masqueraderus
If you use in you localhost, I must install SSL module for PHP engine.

You may use OpenSsl Module

Re: Upgrade of phpmailer library to allow SSL (i.e. GMAIL)

Posted: Sun Mar 01, 2009 6:14 pm
by masqueraderus
Thanks for the prompt reply.
I am reaally new to all this.
Can you guide me on how to install the SSL module?
Thanks in advance

Btw, I am using XAMPP. Does not the installation come with this module?

Re: Upgrade of phpmailer library to allow SSL (i.e. GMAIL)

Posted: Sun Mar 01, 2009 6:37 pm
by tranquang
Step-by-step how to use OpenSSL in XAMPP

1. Open /apache/bin/php.ini file - there are a few php.ini files you could edit, but this one will work everytime.
2. Find the line with ;extension=php_openssl.dll and uncomment it.
3. Restart Apache.

OpenSSL should work fine now on Windows and Linux. You do not need to install any other packages.

Re: Upgrade of phpmailer library to allow SSL (i.e. GMAIL)

Posted: Sun Mar 01, 2009 7:10 pm
by masqueraderus
Hey Man!
Awesome! works like a charm!
These patches should a part of the Joomla release.
Maybe the pros on the forum could suggest that to the dev team!
Thanks a lot again for the help man.

Re: Upgrade of phpmailer library to allow SSL (i.e. GMAIL)

Posted: Thu Mar 05, 2009 6:50 pm
by masqueraderus
Hi Tranquang,

I created another website on the same XAMPP installation, and copied the files to its base directory.
But I am getting the could not connect to SMTP error on the new site.
The old site is working all fine.
The settings in Global Config are same.
Any idea what could be wrong?

Thanks in advance.

Re: Upgrade of phpmailer library to allow SSL (i.e. GMAIL)

Posted: Thu Mar 05, 2009 7:02 pm
by tranquang
may be U user another Gmail account
U must change setting at Gmail website to open smtp function at that.

Good luck

Re: Upgrade of phpmailer library to allow SSL (i.e. GMAIL)

Posted: Thu Mar 05, 2009 7:08 pm
by masqueraderus
Hey!
No I was using the same google account.
But the problem got resolved.
I was using the value of authentication as SSL. I changed that to TSL and the mail went.
The weird thing is, that even if I change back to SSL, the mail goes. Earlier it was not going out on SSL.
But, Thanks for the help!

Re: Upgrade of phpmailer library to allow SSL (i.e. GMAIL)

Posted: Tue Mar 17, 2009 6:11 am
by amw403
how to uncomment the ssl in php.ini

any suggestion

when i open the php.ini, i saw this code

;extension=php_openssl.dll

is this code already uncomment??

Re: Upgrade of phpmailer library to allow SSL (i.e. GMAIL)

Posted: Tue Mar 17, 2009 6:34 am
by mic
no.

Re: Upgrade of phpmailer library to allow SSL (i.e. GMAIL)

Posted: Tue Apr 21, 2009 8:58 pm
by marvinsc
Hello, I was following the mannumix tips til this point

Apply the following changes to add configuration options:
diff -burp joomla.backup/administrator/components/com_config/controllers/application.php [...]

Well, in what place should I do this (apply the changes) ? editing phpmailer.php ?

I've hosted my site in a commercial provider with cpanel acess...

I am so sick tired about this stuff... I am trying to make it works for a very long time (3 days :) )

Re: Upgrade of phpmailer library to allow SSL (i.e. GMAIL)

Posted: Tue Apr 21, 2009 9:30 pm
by marvinsc
Well,

I tryed to execute a testmailer php file and got the following message:

Warning: fsockopen() [function.fsockopen]: unable to connect to ssl://smtp.gmail.com:465 (Connection timed out) in /home/marvinsc/public_html/esde/libraries/phpmailer/smtp.php on line 122
SMTP -> ERROR: Failed to connect to server: Connection timed out (110) Mailer Error: SMTP Error: Could not connect to SMTP host.

Time out ??? unable to connect to ssl://smtp.gmail.com:465 ???

Well... at least i discovered somethin different