how do i make gmail accept the phpmailer from localhost and not prevent signing in?
how do i fix this error message
Message could not be sent.Mailer Error: SMTP connect() failed.
<?php
require 'PHPMailer-master\PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'my@gmail.com'; // SMTP username
$mail->Password = 'valid'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom('my@gmail.com', 'me');
// Add a recipient
$mail->addAddress('their@gmail.com'); // Name is optional
$mail->addReplyTo('my@gmail.com', 'Information');
$mail->addCC('cc@example.com');
$mail->addBCC('bcc@example.com');
$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';
}
?>
It seems a connection to Google SMTP on port 587 is not being made. Are you in a network where port 587 is blocked. You can simply check if a connection can be made by using this telnet command:
telnet smtp.gmail.com 587
You will get a response as shown in snapshot
The Telnet client in Windows is disabled by default, and needs to be enabled via Windows' Programs and Features:
Control Panel --> Programs --> Turn Windows features on or off, in the dialog that pops up check-mark "Telnet Client".
Or you can download Putty
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.