0
votes

I have enabled less secure apps on my account but still the same error. Message could not be sent.Mailer Error: SMTP connect() failed I tried with a free host 000webhost. Here is my code


    require 'PHPMailerAutoload.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 = '[email protected]';                 // SMTP username
    $mail->Password = 'private';                           // SMTP password
    $mail->SMTPSecure = 'ssl';                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 465;                                    // TCP port to connect to

    $mail->setFrom('[email protected]', 'tEst');
    $mail->addAddress('[email protected]');     // Add a recipient
    $mail->addAddress('[email protected]');               // Name is optional
    $mail->addReplyTo('[email protected]', 'Information');
    $mail->addCC('[email protected]');
    $mail->addBCC('[email protected]');

    $mail->isHTML(true);                                  // Set email format to HTML

    $mail->Subject = 'Here is the subject';
    $mail->Body    = 'Hello ,Click On the link to reset password';
    $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';
    }
    ?>

Please Help.

1
What error you receive when script is executed?Sachin PATIL
" but still the same error" - What is the error?WillardSolutions
Message could not be sent.Mailer Error: SMTP connect() faileddcoder

1 Answers

0
votes

does changing to port 587 help?

smtp.Host = "smtp.gmail.com"; smtp.Port = 587;