Can't send an email. Not sure what is going wrong and haven't found an answer through google yet.
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->SMTPSecure = "tls";
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->Username = "myemail@gmail.com";
$mail->Password = "mypassword";
$mail->setFrom("myemail@gmail.com");
$mail->AddAddress("myemail@gmail.com"); // sending an email to myself to check that it works.
$mail->Subject = "Password change for pset7";
$mail->Body = "Hello. Here's a link: pset7/password_mail.php?token=a";
if(!$mail->send())
{
apologize("Something went wrong with sending the link");
}
else
{
redirect("index.php");
}
Edit: Just leaving this here incase someone else has a similar problem with gmail.
On an account that didn't have 2 step authentication I had to enable access for less secure apps before I was able to send mail with phpmailer. You can also debug phpmailer by setting SMTPDebug to 2 or higher. Something like:
$mail->SMTPDebug = 2;