I was having some problems to work mail function in a shared hosting.
See my message
So I decided to use PHP Mailer in SS, and here are the steps to do it.
1) Download PHP Mailer
I downloaded phpmailer for php5
2) Uncompress it to your SS project root.
Rename the uncompressed directory, something like PHPMailer_v2.X.Y, to phpmailer
3) Open your _config.php file
Add this code in the file:
/* { PHPMAILER */
$path = Director::baseFolder().'/phpmailer/';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);
require_once 'class.phpmailer.php';
global $phpmailer;
$phpmailer = new PHPMailer();
$phpmailer->CharSet = "UTF-8";
$phpmailer->IsSMTP(); // send via SMTP
$phpmailer->Host = "smtp.example.com"; // SMTP servers
$phpmailer->SMTPAuth = true; // turn on SMTP authentication
$phpmailer->Username = "username"; // SMTP username
$phpmailer->Password = "password"; // SMTP password
$phpmailer->From = "username@example.com";
$phpmailer->FromName = "My From Text";
/* PHPMAILER } */
This is the basical configuration of PHP Mailer.
4) Open sapphire/core/Email.php
Go to send function and search this line:
$result = htmlEmail($to, $this->from, $subject, $this->body, $this->attachments, $this->plaintext_body, $headers);
replace the line with this lines:
global $phpmailer;
if ($phpmailer)
$result = htmlEmail_phpMailer($to, $this->from, $subject, $this->body, $this->attachments, $this->plaintext_body, $headers);
else
$result = htmlEmail($to, $this->from, $subject, $this->body, $this->attachments, $this->plaintext_body, $headers);
5) Add this new function to Email class:
function htmlEmail_phpMailer($to, $from, $subject, $htmlContent) {
global $phpmailer;
$to = validEmailAddr($to);
$phpmailer->ClearAddresses();
$phpmailer->AddAddress($to);
$phpmailer->IsHTML(true); // send as HTML
$phpmailer->Subject = $subject;
$phpmailer->Body = $htmlContent;
if(!$plainContent)
$plainContent = Convert::xml2raw($htmlContent);
$phpmailer->AltBody = $plainContent;
if(!$phpmailer->Send())
return false;
else
return true;
}
Now SS will send mails using PHP Mailer.
I only test it with forms and it works good. I test it on SS 2.2.1
Maybe it has some errors (any help to solve them is welcomed), but for me it works great.
Hope this helps someone.