skip to Main Content

I am getting the error:

    2020-05-03 02:33:55 SMTP ERROR: Failed to connect to server: (0)
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

I have looked at all GoDaddy articles and stack articles I can find and tried their solutions – such as changing ports, etc. I have also tried with both my Gmail and cPanel web/email accounts. Most solutions out there for this error, however, are not relating to GoDaddy, and their solutions are to do with XAMPP, etc.
Any help is greatly appreciated 🙂

As reference, here is the PHP code:

use PHPMailerPHPMailerPHPMailer;
use PHPMailerPHPMailerSMTP;
use PHPMailerPHPMailerException;


require 'src/Exception.php';
require 'src/PHPMailer.php';
require 'src/SMTP.php';

$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; 
$mail->Host = "localhost";
$mail->Port = 465; 
$mail->IsHTML(true);
$mail->Username = "[email protected]";
$mail->Password = "xxx";
$mail->SetFrom("[email protected]");
$mail->Subject = "Test";
$mail->Body = "hello";
$mail->AddAddress("[email protected]");

 if(!$mail->Send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
 } else {
    echo "Message has been sent";
 }

4

Answers


  1. Chosen as BEST ANSWER

    I have figured out what was wrong: Essentially, I just needed to replace $mail->isSMTP(); with $mail->isMail(); and it worked - just to let anyone else know if they have the same problem!


  2. I apologize if you have provided incorrect information. However, you should make sure that the server’s smtp port is not using 25.

    Login or Signup to reply.
  3. I have the same problem
    i tried with SSL with port 465 then it said services is unavailable
    then i try this thing it solve my problem
    hopefully it solve also yours
    1) Make sure you use
    $mail->IsSMTP(); for the authentication. Ismail is only working for the same server with mail function

    2) This thing fix my problem
    $mail->SMTPSecure = “tsl”;
    $mail->Port = 587;

    i add these two lines now email sending is perfectly working
    earlier i face this error
    SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
    but above thing solve my problem
    hopefully it work for you
    thank you

    Login or Signup to reply.

    Before sending emails using the Gmail’s SMTP Server, you to make some of the security and permission level settings under your Google Account Security Settings.

    1. change

    $mail->host = "localhost";

    to

    $mail->Host = "smtp.gmail.com";

    Use real email for sender and receiver ‘Make sure of the password’

    1. change

    $mail->SMTPSecure = ‘ssl’;

    to

    $mail->SMTPSecure = ‘tls’;

       //tls for localhost and ssl for host server 'onligne'
    

    may work for you 🙂

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search