skip to Main Content

I am trying to sent email using SMTP (PHP Mailer). I am using the aws SMS service. Below is my code:

$mail->isSMTP();
$mail->Host     = 'email-smtp.eu-west-1.amazonaws.com';
$mail->SMTPAuth = true;
$mail->Username = '---';
$mail->Password = '---';
$mail->SMTPSecure = 'tls';
$mail->Port     = 587;

I gat the following result from Debug error:

2024-08-18 05:14:11 SERVER -> CLIENT: 220-wghp7.wghservers.com ESMTP Exim 4.97.1 #2 Sun, 18 Aug 2024 06:14:11 +0100 220-We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail.
2024-08-18 05:14:11 CLIENT -> SERVER: EHLO agrop.co
2024-08-18 05:14:11 SERVER -> CLIENT: 250-wghp7.wghservers.com Hello agrop.co [131.153.147.178]250-SIZE 52428800250-8BITMIME250-PIPELINING250-PIPECONNECT250-AUTH PLAIN LOGIN250-STARTTLS250 HELP
2024-08-18 05:14:11 CLIENT -> SERVER: STARTTLS
2024-08-18 05:14:11 SERVER -> CLIENT: 220 TLS go ahead
SMTP Error: Could not connect to SMTP host.
2024-08-18 05:14:11 CLIENT -> SERVER: QUIT
2024-08-18 05:14:11
2024-08-18 05:14:11
SMTP Error: Could not connect to SMTP host.

2

Answers


  1. Your SMTP host seems to be unavailable. It could be caused due issue with credentials. Please verify that your credentials + SSL/TLS are correct.

    In code setup

    $mail->SMTPSecure = 'ssl';
    $mail->Port = 465;
    

    Check in firewall that you have outbound connections on port 587. Furthermore for Debugging purpose you can enable debug.

    $mail->SMTPDebug = 2;
    

    Please check in your logs.

    Login or Signup to reply.
  2. You can see from the debug output that it’s connecting ok, so the SMTP host is available, and the problem does not lie with firewalls or port numbers. The problem occurs when switching to TLS after issuing STARTTLS, and this is usually caused by misnamed mail servers, transparent redirection, or invalid certificates. This specific scenario is covered extensively in the docs. You will need to set SMTPDebug to 3 or 4 to see what the issue is.

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