21279 Posts in 5729 Topics by 2600 members
General Questions
SilverStripe Forums » General Questions » Change Silverstripe Mailer to use smtp with authentication with the pear package
General questions about getting started with SilverStripe that don't fit in any of the categories above.
Moderators: martimiz, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 2192 Views |
-
Change Silverstripe Mailer to use smtp with authentication with the pear package

22 July 2009 at 1:51am Last edited: 23 February 2010 2:39am
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 ( http://pear.php.net/package/Mail )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 = "smtp.myserver.de";
$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 calledmail(...)
if(!($result = @mail($to, $subject, $fullBody, $headers, "-f$bounceAddress"))) {
$result = mail($to, $subject, $fullBody, $headers);
}to
$result=sendPearMail($to, $subject, $fullBody, $headers);
and last: comment out these lines:
$headers = processHeaders($headers);
That should do it!
Greetings,
Walter
-
Re: Change Silverstripe Mailer to use smtp with authentication with the pear package

22 February 2010 at 8:14am
Hi Walter,
Are you putting the package( http://pear.php.net/package/Mail ) 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... -
Re: Change Silverstripe Mailer to use smtp with authentication with the pear package

23 February 2010 at 1:14am
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)
-
Re: Change Silverstripe Mailer to use smtp with authentication with the pear package

24 February 2010 at 2:15am
I will give it a try and let you know.
Thank you for the attachement.
Cheers -
Re: Change Silverstripe Mailer to use smtp with authentication with the pear package

24 February 2010 at 3:13am
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?
-
Re: Change Silverstripe Mailer to use smtp with authentication with the pear package

22 September 2011 at 12:00am
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.
-
Re: Change Silverstripe Mailer to use smtp with authentication with the pear package

22 September 2011 at 10:02pm
Don't mess around with core - there's a simple module for this feature: https://github.com/xeraa/silverstripe-smtp
| 2192 Views | ||
|
Page:
1
|
Go to Top |





