0
votes

I'm getting error SMTP connect() failed phpmailer with localhost:

2015-09-10 09:34:48 Connection: opening to ssl://smtp.gmail.com:587, timeout=300, options=array ( ) 2015-09-10 09:34:48 SMTP ERROR: Failed to connect to server: (0) 2015-09-10 09:34:48 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

  1. Is it phpmailer cannot run at localhost?
  2. If I want really run at localhost how can I change the code?
  3. I tried using mailto function is work for me but I want change whole thing.
  4. can give any suggestion. I really want to learn it.

    This is the code from github: require 'PHPMailer/PHPMailerAutoload.php';

       $mail = new PHPMailer;
    
       //$mail->SMTPDebug = 4;                               // Enable verbose debug output
    
       $mail->isSMTP();                                      // Set mailer to use SMTP
        $mail->Host = 'smtp.gmail.com';  // Specify main and backup SMTP servers
       $mail->SMTPAuth = true;                               // Enable SMTP authentication
       $mail->Username = '[email protected]';                 // SMTP username
       $mail->Password = 'mygmailpassword';                           // SMTP password
       $mail->SMTPSecure = 'ssl';                            // Enable TLS encryption, `ssl` also accepted
       $mail->Port = 465;                                    // TCP port to connect to
       //$mail->Host = 'tls://smtp.gmail.com:587';
    
       $mail->From = '[email protected]';
       $mail->FromName = 'Mailer';
       $mail->addAddress('[email protected]', 'Joe User');     // Add a recipient
    
       $mail->isHTML(true);                                  // Set email format to HTML
    
       $mail->Subject = 'Here is the subject';
       $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
       $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
    
        if(!$mail->send()) {
           echo 'Message could not be sent.';
           echo 'Mailer Error: ' . $mail->ErrorInfo;
        } else {
          echo 'Message has been sent';
         }
    
2
Can you share the code that might have to be changed? So far, you only posted the error message, as far as I can see.lenz
this is the code I copy from github. I did changed sendmail.ini and php.ini file but still not working.ikramlim

2 Answers

1
votes

PHPMailer is normally working on all systems.

I think you have an old openssl extension or your extension is not enabled. Check that with a phpinfo() if there is openssl enabled.

If not then enable it in your php.ini.

And the other way is that it seems that Google has some problems. When i try to send an Email at the moment i have connection problems with Thunderbird, too. I have to try it some times to connect to gmail.

0
votes

My suggestion is that please try using 'tls' with port 587 instead of 'ssl' with port 587.

Also check whether you are including class.phpmailer.php(ie: require 'class.phpmailer.php';) , If you are doing please comment it and give a try.