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
mail(...)
is calledif(!($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