SMTP Connect () failed. Message not sent. Sender Error: SMTP Connect Error ()

I am trying to send mail to gmail address but it keeps getting this error "SMTP -> ERROR: Failed to connect to server: connection timeout (110) SMTP Connect () failed. Message was not sent. Sender error: SMTP Connect () error . " What could be the problem?

        require 'class.phpmailer.php'; // path to the PHPMailer class
        require 'class.smtp.php';

            $mail = new PHPMailer();


            $mail->IsSMTP();  // telling the class to use SMTP
            $mail->SMTPDebug = 2;
            $mail->Mailer = "smtp";
            $mail->Host = "ssl://smtp.gmail.com";
            $mail->Port = 587;
            $mail->SMTPAuth = true; // turn on SMTP authentication
            $mail->Username = "myemail@gmail.com"; // SMTP username
            $mail->Password = "mypasswword"; // SMTP password 
            $Mail->Priority = 1;

            $mail->AddAddress("myemail@gmail.com","Name");
            $mail->SetFrom($visitor_email, $name);
            $mail->AddReplyTo($visitor_email,$name);

            $mail->Subject  = "Message from  Contact form";
            $mail->Body     = $user_message;
            $mail->WordWrap = 50;  

            if(!$mail->Send()) {
            echo 'Message was not sent.';
            echo 'Mailer error: ' . $mail->ErrorInfo;
            } else {
            echo 'Message has been sent.';
            }

      

+19


source to share


15 replies


Remove or comment out a line -

$mail->IsSMTP();

      



And it will work for you.

I have checked and experimented with many answers from different sites but didn't get any solution other than the above solution.

+45


source


You have to install php_openssl.dll, if you are using wampserver quite easily do a search and apply the PHP extension.

In the example, change this:

    //Set the hostname of the mail server
    $mail->Host = 'smtp.gmail.com';

    //Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission 465 ssl
    $mail->Port = 465;

    //Set the encryption system to use - ssl (deprecated) or tls
    $mail->SMTPSecure = 'ssl';

      



and then you got an email from gmail saying to enable lower secure access apps here https://www.google.com/settings/security/lesssecureapps

I recommend that you change your password and encrypt it constantly

+9


source


You don't have SMTPSecure setup to determine the type of authentication to use and you are using the Host parameter with the unnecessary "ssl: //" (PS - ssl is port 465, if you need to run it over ssl see the accepted answer here . Lines here to add / change:

+ $mail->SMTPSecure = 'tls';

- $mail->Host = "ssl://smtp.gmail.com";
+ $mail->Host = "smtp.gmail.com";

      

+4


source


Are you on Localhost? and do you edit php.ini

?

If not already, try this:
1. Open xampp-> php-> php.ini
2. Search extension=php_openssl.dll


3. Initial will look like this: ;extension=php_openssl.dll


4. Delete ';' and it will look like this: extension=php_openssl.dll


5. If you cannot find extension=php_openssl.dll

, add this line extension=php_openssl.dll

.
6. Then restart Xampp.

Goodluck;)

+4


source


I had this problem to say that I get an email from google telling me that someone is trying to log into your account, so this is you and I answer yes, then it starts working, so if it so, you look in your letter and allow the server

+3


source


Here's a list that you should look into when working with PHPMailer:

  • Enable openSSL without commenting extension=php_openssl.dll

    in your PHP.ini
  • Use $mail->SMTPSecure = 'tls';

    and$mail->Port = 587;

  • Enable debugging if you are wrong elsewhere, like wrong username and password, etc.
+2


source


Sign in to your Google account at myaccount.google.com/security go to "Sign in" and then "Security", scroll down and enable "Allow less secure apps".

+2


source


I know it has been a while since this question, but I had the exact problem and solved it by disabling SMTP_BLOCK on csf.conf (we are using CSF for the firewall).

To disable just edit csf.conf and disable SMTP_BLOCK as follows:

###############################################################################
# SECTION:SMTP Settings
###############################################################################
# Block outgoing SMTP except for root, exim and mailman (forces scripts/users
# to use the exim/sendmail binary instead of sockets access). This replaces the
# protection as WHM > Tweak Settings > SMTP Tweaks
#
# This option uses the iptables ipt_owner/xt_owner module and must be loaded
# for it to work. It may not be available on some VPS platforms
#
# Note: Run /etc/csf/csftest.pl to check whether this option will function on
# this server
# SMTP_BLOCK = "1" --> this will cause phpmailer Connection timed out (110)
SMTP_BLOCK = "0"

      

+1


source


You are all doing well. Just you have to check different SMTP ports like 465 and others that work on your system. One more thing to keep in mind is to allow access to less secure apps through google account, otherwise it will throw the same error.
I went through it all day and the only thing I am doing wrong is the port number. I just changed the port. and it works.

+1


source


To get it to work, I had to go to myaccount.google.com -> "linked apps and sites" and turn "Allow less secure apps" to "ON" (at the bottom of the page).

0


source


If it works on your localhost but not your webhost:

Some hosting sites block certain outgoing SMTP ports . Commenting out the line $mail->IsSMTP();

as mentioned in the accepted answer might make it work, but it just disables your SMTP configuration and uses the hosting site's email configuration.

If you are using GoDaddy, there is no way to send mail using a different SMTP. I used SiteGround and found that they only allow SMTP access from ports 25 and 465 with SSL encryption type, so I would look at the documentation for your host and go from there.

0


source


MailJet

SMTP settings

Port: 25 or 587 (some providers block port 25)

I am working by changing the port after deploying the application to the server.

  • In Debug, this worked for me: $mail->Port = 25;

  • As $mail->Port = 587;

    it works for me:$mail->Port = 587;

GL

0


source


solution configures gmail settings, access to secure application

-2


source


Google recently posted something called App Password. By creating a password app for my mailer instance, I solved the problem.

https://support.google.com/accounts/answer/185833?p=InvalidSecondFactor&visit_id=1-636228492770322608-2743677043&rd=1

-3


source


It also helped me when I commented out the $ mail-> IsSMTP ();

I don't know how to do it though.

-4


source







All Articles