0

I am trying to send mail with PHPMailer (SMTP). If I send from localhost I get the error warning:

2017-11-11 15:14:39 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS 2017-11-11 15:14:40 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\NEU\phpmailer\vendor\phpmailer\phpmailer\src\SMTP.php line 404] SMTP Error: Could not connect to SMTP host. 2017-11-11 15:14:40 CLIENT -> SERVER: QUIT

I've read about changing ssl options like this:

$mail->SMTPOptions = array(
                        'ssl' => array(
                            'verify_peer' => false,
                            'verify_peer_name' => false,
                            'allow_self_signed' => true
                        )
                    );

This is working for me, but I guess there should be another option to fix the problem, since this doesn't fix it on the actual server. On the server the browser just keeps loading for a while until I get an 504 error or even the message:

Failed to load resource: net::ERR_INCOMPLETE_CHUNKED_ENCODING

Now I don't really now how to fix the problem, since I'm really new into this. I've also read about some Problems with ssl certification but didn't come to any conclution...

My Requestcode:

<?php

    // Import PHPMailer classes into the global namespace
    use PHPMailer\PHPMailer\PHPMailer;

    //Load composer's autoloader
    require 'phpmailer/vendor/autoload.php';

    //Empfänger E-Mail
    $recipient = '[email protected]';

    //Formularfelder
    $vname = trim($_POST['vname']);
    $name = trim($_POST['name']);
    $email = trim($_POST['email']);
    $message = trim($_POST['message']);

    if($name != null && $email != null && $message != null) {
        if (!filter_var($email, FILTER_VALIDATE_EMAIL) === false) {

                    $mail = new PHPMailer(true);                                    // Passing `true` enables exceptions

                    //Server settings
                    $mail->isSMTP();                                                // Set mailer to use SMTP
                    $mail->SMTPDebug = 2;
                    $mail->Host = 'smtp.gmail.com';                         // Specify main and backup SMTP servers
                    $mail->SMTPAuth = true;                                     // Enable SMTP authentication
                    $mail->Username = '[email protected]';     // SMTP username
                    $mail->Password = 'passowrd';                       // SMTP password
                    $mail->SMTPSecure = 'tls';                                  // Enable TLS encryption
                    $mail->Port = 587;                                      // TCP port to connect to

                    /*$mail->SMTPOptions = array(
                        'ssl' => array(
                            'verify_peer' => false,
                            'verify_peer_name' => false,
                            'allow_self_signed' => true
                        )
                    );  */

                    //Recipients
                    $mail->setFrom("$recipient", '**');
                    $mail->addAddress("$recipient", '**');     // Add a recipient 
                    $mail->addReplyTo($email, $name);

                    $body = "<p><strong>Name: </strong>$vname $name <br> <strong>Nachricht: </strong>$message</p>";

                    //Content
                    $mail->isHTML(true);                                     // Set email format to HTML
                    $mail->Subject = 'Kontaktformular';
                    $mail->Body    = $body;
                    $mail->AltBody = strip_tags($body);

                    if(!$mail->send()){
                        $signal = 'bad';
                        $msg = 'Mailer Error: ' . $mail->ErrorInfo;
                    } else {
                        $signal = 'ok';
                        $msg = 'Nachricht versendet, vielen Dank!';
                    }

        } else {
            $signal = 'bad';
            $msg = 'Ungültige E-Mail-Adresse, bitte versuchen Sie es erneut.';
        }
    } else {
        $signal = 'bad';
        $msg = 'Bitte füllen Sie alle erforderlichen Felder aus.';
    }

    $data = array(
        'signal' => $signal,
        'msg' =>  $msg
    );

    echo json_encode($data);

?>

I hope that you can help me, if you need some more information just ask for them. I'm sorry that my english isn't the best. Best regards

4
  • Read the troubleshooting guide. It covers exactly this problem, as do many answers on here.
    – Synchro
    Commented Nov 12, 2017 at 15:55
  • i've already read the troubleshooting guide but it didn't help me.
    – philman
    Commented Nov 13, 2017 at 10:09
  • Yet you failed to say what happened when you conducted the openssl tests it describes, which will tell you why the verification failed. It's also possible you're being transparently redirected by your ISP, which is diagnosable from the SMTP transcript you get with SMTPDebug = 2. You omitted the debug output from your Q, so there's no way anyone can help you more specifically. All of this is in the guide.
    – Synchro
    Commented Nov 13, 2017 at 10:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.