Here is the BESTEST way to send emails using PHPmailer library, this is the only method that works for me.
require_once 'mailer/class.phpmailer.php';
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->Host = "smtp.gmail.com";
$mail->Port = 465; // or 587
$mail->IsHTML(true);
$mail->Username = "[email protected]";
$mail->Password = "xxxxxxx";
$mail->SetFrom("[email protected]");
$mail->AddAddress($to);
$logfile = dirname(dirname(__FILE__)) . '/mail.log';
try {
$mail->Body = $message;
$mail->Subject = $subject;
file_put_contents($logfile, "Content: \n", FILE_APPEND);
file_put_contents($logfile, $message . "\n\n", FILE_APPEND);
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Email has been sent";
}
} catch (Exception $e) {
#print_r($e->getMessage());
file_put_contents($logfile, "Error: \n", FILE_APPEND);
file_put_contents($logfile, $e->getMessage() . "\n", FILE_APPEND);
file_put_contents($logfile, $e->getTraceAsString() . "\n\n", FILE_APPEND);
}