2

I am having troubles with PHPMailer. on index.php

    use PHPMailer\PHPMailer\PHPMailer;
    use PHPMailer\PHPMailer\Exception;
    require __DIR__ . '/../vendor/autoload.php';
    require __DIR__ . '/PHPMailer/src/Exception.php';
    require __DIR__ . '/PHPMailer/src/PHPMailer.php';
    require __DIR__ . '/PHPMailer/src/SMTP.php'
    $mail = new PHPMailer;
    require __DIR__ . '/../controllers/login.php';

And login. php

$app->post('/proyectos/login', function ($request) use($servername, $dbname, $dbuser, $dbpassword, $mail) 
{
     $objTmp = $request->getBody();
$obj = array();
parse_str($objTmp, $obj);

$response = array();

$mail->SMTPDebug = 4;
$mail->isSMTP(); 
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'user@gmail.com';
$mail->Password = 'pass';
$mail->SMTPSecure = 'tls';
$mail->Port = 587; 

$mail->setFrom('oneemail@gmail.com', 'sender');
$mail->addAddress('someemail@gmail.com', 'receiver');
$mail->addReplyTo('anotheremail@gmail.com', 'Information');
$mail->isHTML(true);                                

$mail->Subject = 'Just a subject';
$mail->Body    = "Just a body";

if(!$mail->send()) {
    $response['success'] = false;
    $response['message'] = "Could not send email.";

    echo json_encode($response);
    return;

} 
$response['success'] = true;

echo json_encode($response);
return;

2017-12-01 19:54:33 Connection: opening to smtp.gmail.com:587, timeout=300, options=array()
2017-12-01 19:54:34 Connection: opened
2017-12-01 19:54:34 SMTP INBOUND: "220 smtp.gmail.com ESMTP g37sm1362021uah.16 - gsmtp"
2017-12-01 19:54:34 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP g37sm1362021uah.16 - gsmtp
2017-12-01 19:54:34 CLIENT -> SERVER: EHLO localhost
2017-12-01 19:54:34 SMTP INBOUND: "250-smtp.gmail.com at your service, [190.94.198.150]"
2017-12-01 19:54:34 SMTP INBOUND: "250-SIZE 35882577"
2017-12-01 19:54:34 SMTP INBOUND: "250-8BITMIME"
2017-12-01 19:54:34 SMTP INBOUND: "250-STARTTLS"
2017-12-01 19:54:34 SMTP INBOUND: "250-ENHANCEDSTATUSCODES"
2017-12-01 19:54:34 SMTP INBOUND: "250-PIPELINING"
2017-12-01 19:54:34 SMTP INBOUND: "250-CHUNKING"
2017-12-01 19:54:34 SMTP INBOUND: "250 SMTPUTF8"
2017-12-01 19:54:34 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [190.94.198.150]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
2017-12-01 19:54:34 CLIENT -> SERVER: STARTTLS
2017-12-01 19:54:34 SMTP INBOUND: "220 2.0.0 Ready to start TLS"
2017-12-01 19:54:34 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
2017-12-01 19:54:34 Connection failed. Error #2: stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages:error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed [C:\xampp\htdocs\proyectos\public\PHPMailer\src\SMTP.php line 404]
SMTP Error: Could not connect to SMTP host.
2017-12-01 19:54:34 CLIENT -> SERVER: QUIT
2017-12-01 19:54:34
2017-12-01 19:54:34
2017-12-01 19:54:34
2017-12-01 19:54:34 Connection: closed
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
{"success":false,"message":"Could not send email."}

Utai Silva
  • 31
  • 5
  • 1
    Please post the exact error message, Utai. That might help people better understand what is happening. – leanne Dec 01 '17 at 19:02
  • Does PHPMailer send mail out of Slim? I don't think so... https://stackoverflow.com/questions/26827192/phpmailer-ssl3-get-server-certificatecertificate-verify-failed – Gabriel Heming Dec 01 '17 at 19:48

0 Answers0