Connection failed in phpmailer [duplicate]

0

Follow the code friends:

<?php

 header('Access-Control-Allow-Origin: *');
 header("Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE");
 header("Access-Control-Allow-Headers: X-API-KEY, Origin, X-Requested-With, 
 Content-Type, Accept, Access-Control-Request-Method");

 $_POST = json_decode(file_get_contents('php://input'), true);

 require 'phpmailer/phpmailer/PHPMailerAutoload.php';

 $Mailer = new PHPMailer();
 $Mailer->IsSMTP();
 $Mailer->isHTML(true);
 $Mailer->Charset = 'UTF-8';
 $Mailer->SMTPAuth = true;
 $Mailer->SMTPDebug = false;
 $Mailer->SMTPSecure = 'ssl';
 $Mailer->Host = 'smtp.live.com';
 $Mailer->Port = 587;
 $Mailer->Username = '[email protected]';
 $Mailer->Password = 'fakes'; 
 $Mailer->From = '[email protected]';
 $Mailer->FromName = 'Seu Nome';
 $Mailer->Subject = 'Teste';
 $Mailer->Body = 'Mensagem em HTML';
 $Mailer->AltBody = 'Mensagem em texto';
 $Mailer->AddAddress('[email protected]');

 if ($Mailer->Send())
 {
 echo "Enviado com sucesso";
 }
 else 
 {
 echo json_encode($Mailer->SMTPDebug);
 }

Friends, so trying to send mail with this code, ms smp returns an error. Here are the errors:

When trying with debug 1 and 4 respectively:

"2017-04-25 17:03:06    SMTP ERROR: Failed to connect to server:  (0)
 2017-04-25 17:03:06    SMTP connect() failed. 
 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
 1"

"2017-04-25 17:04:05    Connection: opening to ssl://smtp.live.com:587, 
timeout=300, options=array (
                                  )
 2017-04-25 17:04:05    Connection failed. Error #2: stream_socket_client(): 
 SSL operation failed with code 1. OpenSSL Error messages:
                                  error:140770FC:SSL 
 routines:SSL23_GET_SERVER_HELLO:unknown protocol 
 [C:\xampp\htdocs\marcelo\www\phpmailer\phpmailer\class.smtp.php line 294]
 2017-04-25 17:04:05    Connection failed. Error #2: stream_socket_client(): 
 Failed to enable crypto 
 [C:\xampp\htdocs\marcelo\www\phpmailer\phpmailer\class.smtp.php line 294]
 2017-04-25 17:04:05    Connection failed. Error #2: stream_socket_client(): 
 unable to connect to ssl://smtp.live.com:587 (Unknown error) 
 [C:\xampp\htdocs\marcelo\www\phpmailer\phpmailer\class.smtp.php line 294]
 2017-04-25 17:04:05    SMTP ERROR: Failed to connect to server:  (0)
 2017-04-25 17:04:05    SMTP connect() failed. 
 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
 4"

Details * extension = php_openssl.dll is active in php.ini and the pop released in email.

    
asked by anonymous 25.04.2017 / 19:17

1 answer

1

Live uses TLS instead of SSL, just change this:

 $Mailer->SMTPSecure = 'ssl';
 $Mailer->Host = 'smtp.live.com';
 $Mailer->Port = 587;

For this reason:

 $Mailer->SMTPSecure = 'tsl';
 $Mailer->Host = 'smtp.live.com';
 $Mailer->Port = 587;
    
25.04.2017 / 20:11