Try this instead:
$mail = new PHPMailer();
$body = "<h1>hello, world!</h1>"
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = "tls"; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 587; // set the SMTP port for the GMAIL server
$mail->Username = "[email protected]"; // GMAIL username
$mail->Password = "yourpassword"; // GMAIL password
$mail->SetFrom('[email protected]', 'First Last');
$mail->AddReplyTo("[email protected]","First Last");
$mail->Subject = "PHPMailer Test Subject via smtp (Gmail), basic";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$address = "[email protected]";
$mail->AddAddress($address, "John Doe");
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
I think Google doesn't let you use their domain without meeting some conditions, but I think this will work. Code extracted from here: http://phpmailer.worxware.com/?pg=examplebgmail
EDIT
I used the following code exactly and it worked. (I had some trouble with two step authentication but I fixed it. You can use your regular password without worry. If you too have two step authentication enabled you should put there a one time password generated for your e-mail address)
<?php
require("libphp-phpmailer/class.phpmailer.php");
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->Username = "[email protected]";
$mail->Password = "myOneTimePasswordBecauseOfTwoStepAuth";
$mail->setFrom("[email protected]");
$mail->AddAddress("[email protected]");
$mail->Subject = "trial";
$mail->Body = "<h1>hello, world!</h1>";
if ($mail->Send() == false)
{
die($mail->ErrInfo);
}
else
{
echo "It worked!\n";
}
?>