Skip to content
Advertisement

Why does PHPMailer fail to connect to my SMTP server

PHPMailer version: 6.5.0

When I am trying to connect my PHPMailer script with my SMTP server I am getting this error:

SSL loaded 2021-07-07 20:57:08 Connection: opening to mail.solninjaa.com:587, timeout=300, options=array ( 'ssl' => array ( 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true, ),)
2021-07-07 20:57:08 Connection failed. Error #2: stream_socket_client(): php_network_getaddresses: getaddrinfo failed: No such host is known. [C:xampphtdocsphpvendorphpmailerphpmailersrcSMTP.php line 388]
2021-07-07 20:57:08 Connection failed. Error #2: stream_socket_client(): unable to connect to mail.solninjaa.com:587 (php_network_getaddresses: getaddrinfo failed: No such host is known. ) [C:xampphtdocsphpvendorphpmailerphpmailersrcSMTP.php line 388]
2021-07-07 20:57:08 SMTP ERROR: Failed to connect to server: php_network_getaddresses: getaddrinfo failed: No such host is known. (0)
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

The first “SSL loaded” is my script checking if it has OpenSSL enabled.

My mail server is:

mail.solninjaa.com

Note: “mail.solninjaa.com” is the IMAP and POP3 address as well.

I ran a command that would test if the mail server is actually, well, a mail server. It came back saying it wasn’t, which is very weird since I can see it running in my Webmin / Virtualmin dashboard (they are like CPanel). This could be the problem, but I doubt it. I think I might of put in the wrong port (or something like that).

I just thought that was worth mentioning.

My PHPMailer script is:

<?php

use PHPMailerPHPMailerPHPMailer;
use PHPMailerPHPMailerException;


/* Composer autoload.php file includes all installed libraries. */
require '.vendorautoload.php';


$mail = new PHPMailer(TRUE);


$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];

$secretKey = "pleasedontsharethis";
$responseKey = $_POST['g-recaptcha-response'];
$userIP = $_SERVER['REMOTE_ADDR'];
$url = "https://www.google.com/recaptcha/api/siteverify?secret=$secretKey&response=$responseKey&remoteip=$userIP";

$response = file_get_contents($url);
$response = json_decode($response);
    
    
echo (extension_loaded('openssl')?'SSL loaded':'SSL not loaded')."n";

    if ($response->success)
    {
        try {
   
            $mail->setFrom('otheremail@gmail.com', 'SolninjaA');
            $mail->addAddress('email@gmail.com', 'Name');
            $mail->Subject = 'Testing PHPMailer 2';

            $mail->msgHTML(file_get_contents('email_template.html'), __DIR__);

            $mail->AltBody = 'There was a malfunction with sending the HTML. Sorry.';
            // $mail->isSMTP();
            // $mail->Port = 587;
            // $mail->SMTPAuth = TRUE;

            // TESTING CUSTOM STMP SERVERS
            $mail->isSMTP();
            $mail->Host = 'mail.solninjaa.com';
            $mail->SMTPAuth = TRUE;
            $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
            $mail->Username = 'noreply@solninjaa.com';
            $mail->Password = 'mypassword';
            $mail->Port = 587;
            $mail->SMTPAutoTLS = false;
            $mail->SMTPDebug = 3;

               /* Disable some SSL checks. */
            $mail->SMTPOptions = array(
                'ssl' => array(
                'verify_peer' => false,
                'verify_peer_name' => false,
                'allow_self_signed' => true
                )
            );
            
            /* Finally send the mail. */
            $mail->send();
         }
         catch (Exception $e)
         {
            echo $e->errorMessage();
         }
         catch (Exception $e)
         {
            echo $e->getMessage();
         }
         echo "Thank You!" . " -" . "<a href='/dist' style='text-decoration:none;color:#ff0099;'> Return Home</a> we are Automatically redirecting you in 5 seconds.";
         header("Refresh:5; url=/dist");
        }
    else {
        echo "<span style='text-decoration:none;color: red;'>Sorry, something went wrong... Invalid Captcha, please try again.</span> <a href='/dist' style='text-decoration:none;color:#ff0099;'> Return Home</a> we are Automatically redirecting you in 5 seconds.";
        header("Refresh:5; url=/dist");
    }

?>

Note: My original script had XOAUTH2 settings commented out (// , #) but I removed those for security reasons.

Note: My script also requires Google reCaptcha, that’s why there are extra variables.

Also, if I can’t get my custom SMTP servers to work, can I make a Google Workspace account and get a XOAUTH2 token with that account? Will it show my custom email address? (noreply@solninjaa.com)

Advertisement

Answer

It cannot resolve mail.solninjaa.com, and neither can I.

You at least have a DNS problem.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement