Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

    require("PHPMailer-master/src/PHPMailer.php");
    require("PHPMailer-master/src/SMTP.php");
    require("PHPMailer-master/src/Exception.php");		
 
    $mail=new PHPMailer\PHPMailer\PHPMailer();
                  // Enable verbose debug output
    
    $mail->isSMTP();
    $mail->Host='smtp.gmail.com';
    //$mail->Host='smtp.stackmail.com';
    
    $mail->SMTPAuth=true;
    //$mail->Username = '[email protected]';
    // SMTP username
    //$mail->Password =        HIDDEN BY MOD              // SMTP password

     $mail->Username = '[email protected]';
    // SMTP username
    $mail->Password = 'HIDDEN BY MOD';                           // SMTP password
    
    $mail->SMTPSecure = 'STARTTLS'; 
    //$mail->Port = 465;
    $mail->Port = 587;
       
    
    //$mail->From='[email protected]';
    $mail->From='[email protected]';
    $mail->FromName='Syed Ali';
    //$mail->FromName='Omer Nawaz';
    ////[email protected]
    $mail->addAddress('[email protected]','Abdul Ali');                         // Enable TLS encryption, `ssl` also accepted
       // $mail->addAddress('[email protected]','Omer Nawaz');
    //$mail->addReplyTo('[email protected]');
    $mail->WordWrap = 100;
        
    $mail->addAttachment($filename);
    $mail->isHTML(true);
    $mail->Subject='E-INSPECTION CHECKLIST';
    $mail->Body='RECORDS TODAY';
        //$mail->send();

    if(!$mail->send()) 
    {
        echo 'Message could not be sent.<br/>';
        echo 'Mailer Error: ' . $mail->ErrorInfo;
    }
    else{
            echo 'Message sent successfully.';
    }      

}

This is my code it works on localhost in this code pdf to be mail to someone but infinityfree gives error of smtp connect. Kindly help

Turn on less secure apps in https://www.google.com/settings/security/lesssecureapps
And allow access in https://accounts.google.com/b/0/DisplayUnlockCaptcha

3 Likes

Also If you have 2step verification, turn it off. Otherwise it will not work. Also please hide your password. Put **** for example.

2 Likes

What error do you receive EXACTLY?

2 Likes

already done but no result

already mentioned smto connect error

Can you please fill in the topic template next time? So when you’re talking about an issue happening on your website, you actually provide a link which shows that issue?

1 Like

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