Sending emails through SMTP with PHPMailer

前端 未结 8 882
情深已故
情深已故 2020-12-31 07:13

I\'m trying to send SMTP e-mails using PHPMailer, but I keep getting this error message, any ideas how to get rid of it?
I\'m trying to connect via SSL on port 465.

相关标签:
8条回答
  • 2020-12-31 07:25

    Try to send an e-mail through that SMTP server manually/from an interactive mailer (e.g. Mozilla Thunderbird). From the errors, it seems the server won't accept your credentials. Is that SMTP running on the port, or is it SSL+SMTP? You don't seem to be using secure connection in the code you've posted, and I'm not sure if PHPMailer actually supports SSL+SMTP.

    (First result of googling your SMTP server's hostname: http://podpora.ebola.cz/idx.php/0/006/article/Strucny-technicky-popis-nastaveni-sluzeb.html seems to say "SMTPs mail sending: secure SSL connection,port: 465" . )

    It looks like PHPMailer does support SSL; at least from this. So, you'll need to change this:

    define('SMTP_SERVER', 'smtp.ebola.cz');
    

    into this:

    define('SMTP_SERVER', 'ssl://smtp.ebola.cz');
    
    0 讨论(0)
  • 2020-12-31 07:25

    try port 25 instead of 456.

    I got the same error when using port 456, and changing it to 25 worked for me.

    0 讨论(0)
  • 2020-12-31 07:29

    SMTP -> FROM SERVER:
    SMTP -> FROM SERVER:
    SMTP -> ERROR: EHLO not accepted from server:

    that's typical of trying to connect to a SSL service with a client that's not using SSL

    SMTP Error: Could not authenticate.

    no suprise there having failed to start an SMTP conversation authentigation is not an option,.

    phpmailer doesn't do implicit SSL (aka TLS on connect, SMTPS) Short of rewriting smtp.class.php to include support for it there it no way to do what you ask.

    Use port 587 with explicit SSL (aka TLS, STARTTLS) instead.

    0 讨论(0)
  • 2020-12-31 07:32

    Yes, you need OpenSSL to work correctly. My backup testing site worked, my live server didn't. Difference? Live server didn't have OpenSSL within PHP configuration.

    0 讨论(0)
  • 2020-12-31 07:35

    This may seem like a shot in the dark but make sure PHP has been complied with OpenSSL if SMTP requires SSL.

    To check use phpinfo()

    Hope it helps!

    0 讨论(0)
  • 2020-12-31 07:39

    Simple smtp client with php stream socket with tls/ssl smtp STARTTLS command: https://github.com/breakermind/PhpMimeParser/blob/master/PhpSmtpSslSocketClient.php

    works with gmail.com with authenticate:

    <?php
    // Login email and password
    $login = "your-email@cool.xx";
    $pass = "123456";
    
    ini_set('display_errors', 1);
    ini_set('display_startup_errors', 1);
    error_reporting(E_ALL);
    
    $ctx = stream_context_create();
    stream_context_set_option($ctx, 'ssl', 'verify_peer', false);
    stream_context_set_option($ctx, 'ssl', 'verify_peer_name', false);
    try{
        // echo $socket = stream_socket_client('ssl://smtp.gmail.com:587', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);
        echo $socket = stream_socket_client('tcp://smtp.gmail.com:587', $err, $errstr, 60, STREAM_CLIENT_CONNECT, $ctx);
        if (!$socket) {
            print "Failed to connect $err $errstr\n";
            return;
        }else{
            // Http
            // fwrite($socket, "GET / HTTP/1.0\r\nHost: www.example.com\r\nAccept: */*\r\n\r\n");
            // Smtp
            echo fread($socket,8192);
            echo fwrite($socket, "EHLO cool.xx\r\n");
            echo fread($socket,8192);
    
            // Start tls connection
            echo fwrite($socket, "STARTTLS\r\n");
            echo fread($socket,8192);
    
            echo stream_socket_enable_crypto($socket, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT);
    
            // Send ehlo
            echo fwrite($socket, "EHLO cool.xx\r\n");
            echo fread($socket,8192);
    
            // echo fwrite($socket, "MAIL FROM: <hello@cool.com>\r\n");
            // echo fread($socket,8192);
    
            echo fwrite($socket, "AUTH LOGIN\r\n");
            echo fread($socket,8192);
    
            echo fwrite($socket, base64_encode($login)."\r\n");
            echo fread($socket,8192);
    
            echo fwrite($socket, base64_encode($pass)."\r\n");
            echo fread($socket,8192);
    
            echo fwrite($socket, "rcpt to: <to-email@boome.com>\r\n");
            echo fread($socket,8192);
    
            echo fwrite($socket, "DATA\n");
            echo fread($socket,8192);
    
            echo fwrite($socket, "Date: ".time()."\r\nTo: <to-email@boome.com>\r\nFrom:<zour-email@cool.xx\r\nSubject:Hello from php socket tls\r\n.\r\n");
            echo fread($socket,8192);
    
            echo fwrite($socket, "QUIT \n");
            echo fread($socket,8192);
    
            /* Turn off encryption for the rest */
            // stream_socket_enable_crypto($fp, false);
    
            fclose($socket);
        }
    }catch(Exception $e){
        echo $e;
    }
    
    0 讨论(0)
提交回复
热议问题