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, trying to fzr sending email with this code, ms smp returns an error. Follow 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 the email.
In vdd would be $Mailer->Smtpsecure = 'tls'; n? Msm with the change, returns the message "You must provide at least one recipient email address"
– hisoka
@Hisoka this error is another error, just translate the message to understand what is missing "You must provide at least one recipient email", ie you must have removed the line with the function
$mail->AddAddress('[email protected]');
– Guilherme Nascimento
Msm with Addaddress la mano, he returns this msg. Started this msg yesterday, dps q i add the tls. I imagine q is only 1 detail..
– hisoka
@Hisoka I just tested your script with the latest version of phpmailer https://github.com/PHPMailer/PHPMailer/releases/tag/v5.2.23 and it worked perfectly, see: https://pastebin.com/cNx12AVH ... try to see if phpmailer is out of date if it is OK test the script I sent you.
– Guilherme Nascimento
Sorry for the delay, man. I decided using Laravel. Obgd for the help.
– hisoka