Reputation: 21
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 PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
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";
}
Upvotes: 0
Views: 2270
Reputation: 1
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.
$mail->host = "localhost";
to
$mail->Host = "smtp.gmail.com";
Use real email for sender and receiver 'Make sure of the password'
$mail->SMTPSecure = 'ssl';
to
$mail->SMTPSecure = 'tls';
//tls for localhost and ssl for host server 'onligne'
may work for you :)
Upvotes: 0
Reputation: 1
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
Upvotes: 0
Reputation: 21
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!
Upvotes: 2
Reputation: 45
I apologize if you have provided incorrect information. However, you should make sure that the server's smtp port is not using 25.
Upvotes: 0