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.