Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SMTP Error: Could not connect to SMTP host

I have this code, and all works well in my local server. The email is sent without any problem.

But now I pass the content to webserver, and I get this error...

SMTP Error: Could not connect to SMTP host.

SSL is enable in the server..correct? so, what is the problem? enter image description here

            $mail = new PHPMailer();
            $mail->IsSMTP();
            $mail->SMTPAuth   = true;                  // enable SMTP authentication
            $mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
            $mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
            $mail->Port       = 465;                   // set the SMTP port
            $mail->Username   = "dnteiro"; // GMAIL username
            $mail->Password   = "xxx";      // GMAIL password
like image 718
anvd Avatar asked Feb 25 '23 00:02

anvd


1 Answers

It sounds like your web host is blocking outbound connections to smtp.gmail.com:465. Suggestions:

  1. Verify: If you have shell/terminal access to your web hosting server, try a telnet test to verify that they are in fact blocking this. Run telnet smtp.gmail.com 465

  2. Contact: Call or email your hosting provider and find out what SMTP server they provide for outbound relay. Make sure they know you want to use your @gmail.com address as the From/Reply-to address.

  3. Update code: Once your host provides you with a different mail server, update your code and try again.

If your web host doesn't allow outbound relay from its servers at all, then you need to look at switching hosts, if this is a requirement for your application.

like image 107
AJ. Avatar answered Feb 26 '23 20:02

AJ.