SMTP Issues

Hello I am trying to send emails through SMTP emails using php mailer. Here is my code. It worked before coming to Cloudflare. I have attached my email dns records. I have also tried putting the origin servers IP as the host.

<?php use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; //Load Composer's autoloader require 'vendor/autoload.php'; $mail = new PHPMailer(true); try { //Server settings $mail->SMTPDebug = 2; $mail->isSMTP(); $mail->Host = ''; $mail->SMTPAuth = true; $mail->Username = 'usernamegoeshere'; $mail->Password = 'passwordgoeshere'; $mail->SMTPSecure = 'tls'; $mail->Port = 587; //Recipients $mail->setFrom('fromemailgoeshere', 'TickyTimer'); $mail->addAddress('toemailgoeshere'); $mail->addReplyTo('replyemailgoeshere'); //Content $mail->IsHTML(true); $mail->Subject = 'Testing Email Server'; $mail->Body = '


'; $mail->send(); echo 'Message has been sent'; } catch (Exception $e) { echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo; } ?>

I get the following response.
2019-04-04 17:56:23 CLIENT -> SERVER: STARTTLS
2019-04-04 17:56:23 SERVER -> CLIENT: 220 TLS go ahead
SMTP Error: Could not connect to SMTP host.
2019-04-04 17:56:23 CLIENT -> SERVER: QUIT
2019-04-04 17:56:23
2019-04-04 17:56:23
SMTP Error: Could not connect to SMTP host.
Message could not be sent. Mailer Error: SMTP Error: Could not connect to SMTP

If you have SSH access to the server, could you tell the output of this command:

1 Like

Check your local or servers DNS cache. A dig Like @Judge mentioned will show If it’s resolving correctly. Additionally check your firewall settings if there’s outgoing traffic blocked to port 25

telnet 25 Trying 198.xx.xx.xx…
Connected to
Escape character is ‘^]’. ESMTP Exim 4.91 #1 Thu, 04 Apr 2019 16:14:07 -0400
220-We do not authorize the use of this system to transport unsolicited,
220 and/or bulk e-mail.
250 Hello [62.xx.xx.xx]
250 Reset OK
221 closing connection
Connection closed by foreign host

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.