SMTP connect() failed... while i am trying to send mail from my php file

15,575

I found a solution for this problem,

Check whether your PHP is using openSSL extension or not...!

  1. Edit your php.ini from your installed php folder
  2. Search for extension=php_openssl.dll
  3. The initial will look like this ;extension=php_openssl.dll
  4. Remove the ';' and it will look like this extension=php_openssl.dll
  5. If you can't find the extension=php_openssl.dll, add this line extension=php_openssl.dll.
  6. Then restart your Xampp or LAMP or APACHE server (depends upon which of these you're using).

Hope this method would solve your problem...

Share:
15,575

Related videos on Youtube

elayaraja
Author by

elayaraja

Updated on September 15, 2022

Comments

  • elayaraja
    elayaraja over 1 year

    i ve been trying to send mail from my php file, i got an error like this

    **"SMTP ERROR: Failed to connect to server: php_network_getaddresses: getaddrinfo failed: No such host is known. (0) SMTP connect() failed."**
    

    i am in the deadline of my project, if anybody knows the solution or error what i have done over here, please share and help. i am sharing my code here.........

    <?php
        require("C:/xampp/htdocs/conference/PHPMailer-master/class.phpmailer.php");
        require("C:/xampp/htdocs/conference/PHPMailer-master/class.smtp.php");
    
        $mail = new PHPMailer();
    
        $mail->IsSMTP();  // telling the class to use SMTP
        $mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
        $mail->SMTPAuth   = true; // SMTP authentication
        $mail->SMTPSecure = 'tls'; // secure transfer enabled REQUIRED for GMail
        $mail->Host       = "smtp.gmail.com"; // SMTP server
        $mail->Port       = 465; // SMTP Port
        $mail->Username   = "my email address"; // SMTP account username
        $mail->Password   = "my password";        // SMTP account password
    
        $mail->SetFrom('my email address', 'xxxx'); // FROM
        $mail->AddReplyTo('my email address', 'xxxx'); // Reply TO
    
        $mail->AddAddress('someone email address', 'yyyy'); // recipient email
    
        $mail->Subject    = "First SMTP Message"; // email subject
        $mail->Body       = "Hi! \n\n This is my first e-mail sent through Google SMTP using PHPMailer.";
    
        if(!$mail->Send()) {
          echo 'Message was not sent.';
          echo 'Mailer error: ' . $mail->ErrorInfo;
        } else {
          echo 'Message has been sent.';
        }
    ?>
    
  • MichaelP
    MichaelP over 10 years
    Try to lookover every variable in this document and see if it matches yours. Click here. For example, your Username and Password shouldn't be in double-quotes too. Take your time and carefully read. 's are known to sneakily mess things up. Also, please use ssl://smtp.gmail.com. This lets your program know that it should use an protocol.