-3

hi my phpmailer is producing the following result when i execute my mailtest.php

Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

i have gone through many questions about phpmailer in this forum but none has benefit me.

my mailtest.php

     <?php
       require ("/phpmailer/PHPMailerAutoload.php");
       require ("/phpmailer/class.phpmailer.php");

       $mail = new PHPMailer;

       //$mail->SMTPDebug = 3;                               // 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 = 'thethih@gmail.com';                 // SMTP username
       $mail->Password = 'password.';                           // SMTP password
       $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
       $mail->Port = 587;                                    // TCP port to connect to

       $mail->setFrom('from@example.com', 'Mailer');
       $mail->addAddress('thethih@gmail.com', 'Joe User');     // Add a recipient
       $mail->addAddress('thethih@yahoo.com');               // Name is optional
       $mail->addReplyTo('info@example.com', 'Information');
       $mail->addCC('cc@example.com');
       $mail->addBCC('bcc@example.com');


       $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';
        }

     ?>

any help will be appreciated .. and it is in localhost.

hardeep
  • 93
  • 2
  • 12
  • hide your credentials!! – Thamilhan May 02 '16 at 16:45
  • password. is not the actual password..thanks – hardeep May 02 '16 at 16:46
  • @JoseManuelAbarcaRodríguez not working still – hardeep May 02 '16 at 16:47
  • http://php.net/manual/en/function.error-reporting.php – Funk Forty Niner May 02 '16 at 16:47
  • 1
    you should also uncomment this out `//$mail->SMTPDebug = 3;` that's your built-in debugger. – Funk Forty Niner May 02 '16 at 16:48
  • 3
    **Can we assume you read the link that phpMailer produced for you**? Or should we reproduce the section for you to read here and waste our time as well as yours??? – RiggsFolly May 02 '16 at 16:49
  • this may help you: http://stackoverflow.com/questions/2386544/error-handling-with-phpmailer – Black Sheep May 02 '16 at 16:51
  • I've had problems using TLS on gmail's 587 port. SSL for some reason worked though. Also, if your account has 2-step verification on, you probably want to disable that. – Scratch'N'Purr May 02 '16 at 16:52
  • another possible issue could be that if you have an SPF record and that google isn't included and is only made to work with your domain/host, then that could fail you. Make sure your system is setup for mail. – Funk Forty Niner May 02 '16 at 16:53
  • @Fred-ii- i uncommented the line gives me the following message 2016-05-02 16:59:26 SMTP ERROR: Failed to connect to server: (0) 2016-05-02 16:59:26 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 – hardeep May 02 '16 at 17:04

1 Answers1

1

On GitHub, PHPMailer says "Compatible with PHP 5.0 and later", but that may not be the case.

Try changing your version of PHP to 5.5 and see if that fixes the problem. You can change your version of PHP by going to control panel and clicking on PHP Configuration.

uhohcode
  • 26
  • 3