Setting up CS-Cart to send e-mails via Gmail SSL / Google Apps

November 30th, 2010 by Alex Leave a reply »

This is the pita which may make you spend all your day trying to find proper configs for CS-Cart. Basically, we all know there’s the url for SSL Gmail server: it’s ssl://
Sounds simple to set up, but not so fast fella’..

  • First of all, in the e-mail configuration page, choose the Method of sending e-mails: via SMTP server, set the host to, put your username/password credentials and tick the use smtp authentification (though we don’t care about it if we’re doing it the way I did).
  • Next, download a fresh library of PHPMailer. We’re using it because cs-cart already uses it, but some kind of weird version (it doesn’t have some properties we may need for SSL). So, anyway we’re downloading our standalone PHPMailer package.
  • Upload it somewhere in cs-cart. Let’s say into a root phpmailer folder.
  • Now, we’ll link cs-cart to this package. Locate the core/class.mailer.php file and locate the require statement. Change it to something like this.. in our case it’s
    require(DIR_ROOT . '/phpmailer/class.phpmailer.php');
  • Comment the class Mailer declaration and substitute it with a dummy override, so all the file looks like this:
    if ( !defined('AREA') )	{ die('Access denied');	}
    require(DIR_ROOT . '/phpmailer/class.phpmailer.php');
    class Mailer extends PHPMailer {}
    class Mailer extends PHPMailer
        function SetLanguage($lang_type, $lang_path = "language/") 
    		$lang_path = DIR_LIB . '/phpmailer/' . $lang_path;
    		return parent::SetLanguage($lang_type, $lang_path);
        function AddImageStringAttachment($string, $filename, $encoding = "base64", $type = "application/octet-stream") 
            // Append to $attachment array
            $cur = count($this->attachment);
            $this->attachment[$cur][0] = $string;
            $this->attachment[$cur][1] = $filename;
            $this->attachment[$cur][2] = $filename;
            $this->attachment[$cur][3] = $encoding;
            $this->attachment[$cur][4] = $type;
            $this->attachment[$cur][5] = true; // isString
            $this->attachment[$cur][6] = "inline";
            $this->attachment[$cur][7] = $filename;
    	function RFCDate()
    		return date('r');

    Save and upload back to the server

  • Now locate the core/fn.init.php file, then locate the line function fn_init_mailer(). In that function you will find the condition if ($mailer_settings[‘mailer_send_method’] == ‘smtp’). Add some more lines to it so it looks like this:
    if ($mailer_settings['mailer_send_method'] == 'smtp') {
    	$mailer->SMTPAuth = ($mailer_settings['mailer_smtp_auth'] == 'Y') ? true : false;
    	$mailer->Host = $mailer_settings['mailer_smtp_host'];
    	$mailer->Username = $mailer_settings['mailer_smtp_username'];
    	$mailer->Password = $mailer_settings['mailer_smtp_password'];
    	if (strpos($mailer_settings['mailer_smtp_host'], '') !== false) {			
    		$mailer = new PHPMailer();
    		$mailer->Username = $mailer_settings['mailer_smtp_username'];
    		$mailer->Password = $mailer_settings['mailer_smtp_password'];
    		$mailer->Host = '';
    		$mailer->Port = 465;
    		$mailer->Mailer = 'mail';
    		$mailer->SMTPSecure = 'ssl';
    		$mailer->SMTPAuth = true;

This may look complicated but it works like a clock. In this case we are just substituting the native PHPMailer that CS-Cart has with our own distribution leaving the structure CS-Cart wants.

As a conclusion, here are the parameters I used in CS-Cart e-mail settings page:

Method of sending e-mails: via SMTP server
SMTP host:
SMTP username: your full e-mail
SMTP password: e-mail password

Any other fields actually don’t matter in our case. Enjoy, my CS-Cart friends 😀

This page can be found by searching for:

cs-cart gmail

1 comment

  1. Steve says:

    It is cool, thank you! Now try to do it. This solution is good that all letters must be stored in the Outbox.