简体   繁体   中英

PHPMailer, SMTP Failed to connect to server

I'm using PHPMailer. But when i upload to my host i get the error SMTP connect() failed.

My environment 1. Server OS:CentOS 7 2. Web Services: XAMPP 5.6.8 3. PHPMailer:5.2.4

this is my code:

<?php
    require_once('PHPMailer_old/class.phpmailer.php');
    try{
    $mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch
    $mail->IsSMTP(); // telling the class to use SMTP
    $mail->SMTPDebug  = 1;                     // enables SMTP debug information (for testing)
    $mail->SMTPAuth   = true;                  // enable SMTP authentication
    $mail->SMTPSecure = "ssl";
    $mail->SMTPAutoTLS = false;        // close TLS
    $mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
    $mail->Port       = 465;                   // set the SMTP port for the GMAIL server
    $mail->Username   = "Test@gmail.com";  // GMAIL username
    $mail->Password   = "Test";  // GMAIpassword

    $mail->FromName = "Test Manager";
    $mail->From = "Test@gmail.com";
    $to = "Test@hotmail.com";
    $mail->AddAddress($to);
    $mail->Subject  = "First PHPMailer Message";
    $mail->AltBody    = "To view the message, please use an HTML compatible email viewer!";
    $mail->WordWrap   = 80;
    $body = "success!";
    $mail->MsgHTML($body);
    $mail->IsHTML(true);
    $mail->Send();
    echo "Message has been sent.";
    }catch(phpmailerException $e){
        echo "Sending Failed";
        echo $e -> errorMessage();
    }
    ?>

Error Message In web: SMTP -> ERROR: Failed to connect to server: (0) Sending FailedSMTP Error: Could not connect to SMTP host.

Thanks Everyone Help! My Solution is uninstall XAMPP and respectively install apache, PHP, MySQL

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM