1

PHPMailer is not working and throwing following error.

2017-12-04 13:34:14 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP y19sm20173980pgv.19 - gsmtp
2017-12-04 13:34:14 CLIENT -> SERVER: EHLO solutions.proprompt.com
2017-12-04 13:34:14 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [103.58.144.11]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
2017-12-04 13:34:14 CLIENT -> SERVER: STARTTLS
2017-12-04 13:34:14 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
SMTP Error: Could not connect to SMTP host.
2017-12-04 13:34:14 CLIENT -> SERVER: QUIT
2017-12-04 13:34:15
2017-12-04 13:34:15
SMTP Error: Could not connect to SMTP host.
Message could not be sent.Mailer Error: SMTP Error: Could not connect to SMTP host.

It was working properly before. I have used following lines of code:

$mail->SMTPDebug = 2;                                 // 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 = 'some@email.com';                 // SMTP username
    $mail->Password = 'somepassword';                           // SMTP password
    $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 587;  

Can anyone tell me where it went wrong?

M Khalid Junaid
  • 63,861
  • 10
  • 90
  • 118
Anon
  • 523
  • 1
  • 7
  • 25
  • 4
    **Donot** post your credentials here – M Khalid Junaid Dec 04 '17 at 13:38
  • 1
    Read the [PHPMailer help topics](https://github.com/PHPMailer/PHPMailer/blob/master/examples/gmail.phps) – Martin Dec 04 '17 at 13:45
  • 1
    I'm voting to close this question as off-topic because this question is specifically and fully answered on the gitHub repository of the software in question (PhpMailer). – Martin Dec 04 '17 at 13:50
  • Related answer: https://stackoverflow.com/questions/26827192/phpmailer-ssl3-get-server-certificatecertificate-verify-failed/28759959#28759959 – William Isted Dec 04 '17 at 14:11

3 Answers3

4

After hours of struggling , I found your answer to be correct, Those who are facing issues with PHPMailer and godaddy linux hosting server have to some simple changes ,

host = 'localhost'
and add the below lines
$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);

should work

Jagadish Meghval
  • 199
  • 1
  • 11
3

Following lines of code solved this issue.

$mail->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
Anon
  • 523
  • 1
  • 7
  • 25
1

Followed code worked for me:

    $mail = new PHPMailer(true);

    $mail->isSMTP();// Set mailer to use SMTP
    $mail->CharSet = "utf-8";// set charset to utf8
    $mail->SMTPAuth = true;// Enable SMTP authentication
    $mail->SMTPSecure = 'tls';// Enable TLS encryption, `ssl` also accepted

    $mail->Host = 'smtp.gmail.com';// Specify main and backup SMTP servers
    $mail->Port = 587;// TCP port to connect to
    $mail->SMTPOptions = array(
        'ssl' => array(
            'verify_peer' => false,
            'verify_peer_name' => false,
            'allow_self_signed' => true
        )
    );
    $mail->isHTML(true);// Set email format to HTML

    $mail->Username = 'Sender Email';// SMTP username
    $mail->Password = 'Sender Email Password';// SMTP password

    $mail->setFrom('MAIL_USERNAME', 'Test');//Your application NAME and EMAIL
    $mail->Subject = 'Test';//Message subject
    $mail->MsgHTML('HTML code');// Message body
    $mail->addAddress('User Email', 'User Name');// Target email


    $mail->send();
Dumitru Boaghi
  • 183
  • 2
  • 4