In my code I am just trying to send an email to a recipient using the PhPmailer tool but every time I do i get errors. I've watched numerous amounts of video tutorials on this and looked at tons of websites but no fix. I've tried changing my port from "587 to 465", change the "SMTPDebug = 2" to see clear error message, I even tried troubleshooting from the github page but I am still having no luck. Here is my code
<?php
require 'PHPMailerAutoload.php';
require 'credential.php';
$mail = new PHPMailer;
$mail->SMTPDebug = 4; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp1.gmail.com;'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = EMAIL; // SMTP username
$mail->Password = PASS; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom(EMAIL, 'Testing this');
$mail->addAddress('testemail123@outlook.com'); // Add a recipient // Name is optional
$mail->addReplyTo(EMAIL);
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
?>
Errors Messages
2018-02-23 07:16:07 Connection: opening to smtp.gmail.com:587, timeout=300, options=array ()
2018-02-23 07:16:07 Connection: opened
2018-02-23 07:16:07 SMTP -> get_lines(): $data is ""
2018-02-23 07:16:07 SMTP -> get_lines(): $str is "220 smtp.gmail.com ESMTP s125sm758477vkb.40 - gsmtp"
2018-02-23 07:16:07 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP s125sm758477vkb.40 - gsmtp
2018-02-23 07:16:07 CLIENT -> SERVER: EHLO localhost
2018-02-23 07:16:07 SMTP -> get_lines(): $data is ""
2018-02-23 07:16:07 SMTP -> get_lines(): $str is "250-smtp.gmail.com at your service, [x.x.x.x]"
2018-02-23 07:16:07 SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [x.x.x.x]"
2018-02-23 07:16:07 SMTP -> get_lines(): $str is "250-SIZE 35882577"
2018-02-23 07:16:07 SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [x.x.x.x]250-SIZE 35882577"
2018-02-23 07:16:07 SMTP -> get_lines(): $str is "250-8BITMIME"
2018-02-23 07:16:07 SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [x.x.x.x]250-SIZE 35882577250-8BITMIME"
2018-02-23 07:16:07 SMTP -> get_lines(): $str is "250-STARTTLS"
2018-02-23 07:16:07 SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [x.x.x.x]250-SIZE 35882577250-8BITMIME250-STARTTLS"
2018-02-23 07:16:07 SMTP -> get_lines(): $str is "250-ENHANCEDSTATUSCODES"
2018-02-23 07:16:07 SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [x.x.x.x]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES"
2018-02-23 07:16:07 SMTP -> get_lines(): $str is "250-PIPELINING"
2018-02-23 07:16:07 SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [x.x.x.x]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING"
2018-02-23 07:16:07 SMTP -> get_lines(): $str is "250-CHUNKING"
2018-02-23 07:16:07 SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [x.x.x.x]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING"
2018-02-23 07:16:07 SMTP -> get_lines(): $str is "250 SMTPUTF8"
2018-02-23 07:16:07 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [x.x.x.x]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
2018-02-23 07:16:07 CLIENT -> SERVER: STARTTLS
2018-02-23 07:16:07 SMTP -> get_lines(): $data is ""
2018-02-23 07:16:07 SMTP -> get_lines(): $str is "220 2.0.0 Ready to start TLS"
2018-02-23 07:16:07 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
2018-02-23 07:16:07 Connection failed. Error #2: stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages:error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed [C:\wamp64\www\mailer\phpmailer\class.smtp.php line 375]
SMTP Error: Could not connect to SMTP host.
2018-02-23 07:16:07 CLIENT -> SERVER: QUIT
2018-02-23 07:16:07 SMTP -> get_lines(): $data is ""
2018-02-23 07:16:07
2018-02-23 07:16:07
2018-02-23 07:16:07
2018-02-23 07:16:07
2018-02-23 07:16:07
2018-02-23 07:16:07 Connection: closed
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting