Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Change Silverstripe Mailer to use smtp with authentication with the pear package


7 Posts   3132 Views


22 July 2009 at 1:51am (Last edited: 23 February 2010 2:39am), Community Member, 18 Posts

I tried a lot to use silverstripe with a smtp server with authentication.

First I followed the proposals given in the forum "How to use PhpMailer with Silverstripe".
This was working, but: The PhpMailer class does not generate correct mails for use with outlook clients, especially with html formatted emails. As I did not see any solution for phpmailer, I found the Mail package in the Pear packages ( )

After making some simple changes to "Mailer.php" in Saphhire/Email mails are generated now correctly also for outlook clients.

The change for Mailer.php was:
Insert at the end of Mailer.php

* Send a email via Pear mail package
function sendPearMail($to, $subject, $body, $headers /* , "-f$bounceAddress") */ ) {
   require_once "PEAR.php";
   require_once "Mail.php";

   $headers["Subject"] = $subject;
   $headers["To"] = $to;

   $from = $headers["From"] ;
   $host = "";
   $username = "myusername";
   $password = "mypassword";

   $smtp = Mail::factory('smtp',
    array ('host' => $host,
      'auth' => true,
      'username' => $username,
      'password' => $password));

   $mail = $smtp->send($to, $headers, $body);
   if (PEAR::isError($mail)) {
    // echo("<p>" . $mail->getMessage() . "</p>");
    return FALSE;
    } else {
    // echo("<p>Message successfully sent!</p>");
    return TRUE;

and change all lines where


is called

if(!($result = @mail($to, $subject, $fullBody, $headers, "-f$bounceAddress"))) {
      $result = mail($to, $subject, $fullBody, $headers);


$result=sendPearMail($to, $subject, $fullBody, $headers);

and last: comment out these lines:

      $headers = processHeaders($headers);

That should do it!




22 February 2010 at 8:14am Community Member, 31 Posts

Hi Walter,
Are you putting the package( ) to the root of SS first?
And then applying the changes to Mailer.php?
It would also be nice if you could attach your Mailer.php to this post as to prevent mistakes.
Sorry for being a noob...


23 February 2010 at 1:14am Community Member, 18 Posts

My provider installed the pear package for us, so I had not to change the Silverstripe source directory.
The corresponding output of phpinfo is:
Configure Command   

'./configure' '--prefix=/usr/' '--datadir=/usr/share/php/' '--bindir=/usr/bin/' '--libdir=/usr/share/' '--with-exec-dir=/usr/lib/php/bin/' '--with-config-file-path=/etc' '--with-config-file-scan-dir=/etc/php5-config' '--enable-discard-path' '--enable-force-cgi-redirect' '--enable-memory-limit' '--enable-sigchild' '--enable-track-vars' '--enable-trans-sid' '--disable-mysql' '--disable-pdo' '--disable-dom' '--enable-bcmath' '--enable-calendar' '--enable-ctype' '--enable-dbase' '--enable-exif' '--enable-filepro' '--enable-ftp' '--enable-magic-quotes' '--enable-mbstr-enc-trans' '--enable-mbstring' '--enable-mbregex' '--enable-shmop' '--enable-sysvsem' '--enable-sysvshm' '--enable-wddx' '--with-gettext' '--with-mcrypt' '--with-iconv' '--with-mcal' '--with-mcrypt' '--with-zlib' '--with-bz2' '--with-gmp' '--with-openssl=/usr' '--with-pear' '--enable-zip' '--with-recode' '--enable-suhosin' '--with-apxs2=/usr/sbin/apxs'

I append the changed Mailer.php (now it's version 2.3.6)


24 February 2010 at 2:15am Community Member, 31 Posts

I will give it a try and let you know.
Thank you for the attachement.


24 February 2010 at 3:13am Community Member, 509 Posts

I really wish there was a way to do this without hacking the core files. Maybe if there was a sendMail() method that follows the current behaviour, but can be easily overwritten by using Object::add_extension()?

Any thoughts?


22 September 2011 at 12:00am Community Member, 30 Posts

Hi Walter, how do I do to integrate/install the pear package in SS, my hosting provider doesn't want install it for me (!)
Thanks in advance. :)


22 September 2011 at 10:02pm Google Summer of Code Hacker, 58 Posts

Don't mess around with core - there's a simple module for this feature: