Am trying to send mail to a gmail address but it keeps on getting this error "SMTP -> ERROR: Failed to connect to server: Connection timed out (110)SMTP Connect() failed. Message was not sent.Mailer error: SMTP Connect() failed." What could be the problem?
require 'class.phpmailer.php'; // path to the PHPMailer class
require 'class.smtp.php';
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPDebug = 2;
$mail->Mailer = "smtp";
$mail->Host = "ssl://smtp.gmail.com";
$mail->Port = 587;
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "myemail@gmail.com"; // SMTP username
$mail->Password = "mypasswword"; // SMTP password
$Mail->Priority = 1;
$mail->AddAddress("myemail@gmail.com","Name");
$mail->SetFrom($visitor_email, $name);
$mail->AddReplyTo($visitor_email,$name);
$mail->Subject = "Message from Contact form";
$mail->Body = $user_message;
$mail->WordWrap = 50;
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}
Remove or comment out the line-
And it will work for you.
I have checked and experimented many answers from different sites but haven't got any solution except the above solution.
To get it working, I had to go to myaccount.google.com -> "connected apps & sites", and turn "Allow less secure apps" to "ON" (near the bottom of the page).
Mailjet
SMTP SETTINGS
I work by changing the port after deploying the app to the server.
$mail->Port = 25;
$mail->Port = 587;
GL
i've had this problem in tell i recive an email from google telling me that someone try to login to your account is it you and i answer yes then it start workin so if this is the case for you look in your email and allow the server
You must to have installed php_openssl.dll, if you use wampserver it's pretty easy, search and apply the extension for PHP.
In the example change this:
and then you recived an email from gmail talking about to enable the option to Less Safe Access Applications here https://www.google.com/settings/security/lesssecureapps
I recommend you change the password and encrypt it constantly
Are you running on Localhost? and have you edit the
php.ini
?If not yet, try this:
1. Open xampp->php->php.ini
2. Search for
extension=php_openssl.dll
3. The initial will look like this
;extension=php_openssl.dll
4. Remove the ';' and it will look like this
extension=php_openssl.dll
5. If you can't find the
extension=php_openssl.dll
, add this lineextension=php_openssl.dll
.6. Then restart your Xampp.
Goodluck ;)