0

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 = 'mygmail@gmail.com';                 // 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 = 'ikramlim@gmail.com';
       $mail->FromName = 'Mailer';
       $mail->addAddress('ikramlim@gmail.com', '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';
         }
    
ikramlim
  • 103
  • 1
  • 2
  • 12
  • 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 Sep 10 '15 at 09:52
  • this is the code I copy from github. I did changed sendmail.ini and php.ini file but still not working. – ikramlim Sep 10 '15 at 10:10

2 Answers2

1

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.

René Höhle
  • 26,716
  • 22
  • 73
  • 82
0

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.

Murali
  • 1,084
  • 1
  • 11
  • 28
  • still getting error too changed port 465 to 587, and require 'PHPMailer/class.phpmailer.php'; – ikramlim Sep 10 '15 at 10:23
  • Please try giving this as tls instead of ssl. $mail->SMTPSecure = 'ssl'; – Murali Sep 10 '15 at 10:24
  • Try going through this post . check whether it helps for you . http://stackoverflow.com/questions/18496650/smtp-connect-failed-message-was-not-sent-mailer-error-smtp-connect-failed – Murali Sep 10 '15 at 10:40
  • Hi @Murali thanks alot.. I solved this problem. Thank you so much – ikramlim Sep 10 '15 at 14:42