I have just started coding in PHP. I'm trying to send a mail but it throws an error Mailer Error: SMTP connect() failed.
Below is the code i am using :
date_default_timezone_set('Etc/UTC');
require 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = gethostbyname('ssl://smtp.gmail.com');
$mail->SMTPAuth = true;
$mail->AuthType = 'LOGIN';
$mail->Username = 'abc@gmail.com';
$mail->Password = '********';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->setFrom('abc@gmail.com','Abc') ;
$mail->addReplyTo('abc@gmail.com');
$mail->addAddress("abc@gmail.com",'No REPLY');
$mail->isHTML(true);
$mail->Body = "12345";
$mail->Subject = "<b>OTP for password reset<b>";
$mail->Body = "Hi! Your OTP is : ";
if(!$mail->Send()) {
echo 'Message was not sent.';
echo "Mailer Error: " . $mail->ErrorInfo;
}
else {
echo 'Message has been sent.';
}
Any help would be appreciated.