PHPMailer send email issues

Created on 30 Nov 2017  路  3Comments  路  Source: PHPMailer/PHPMailer

I have an email class to send confirmation email after sign up
here is my construct function:
public function __construct() {

    //Server settings
    $this->objMailer = new PHPMailer(true);

    $this->objMailer->SMTPDebug = 2;
    $this->objMailer->isSMTP();
    $this->objMailer->Host = "smtp.gmail.com";
    $this->objMailer->SMTPAuth = true;
    $this->objMailer->Username = "

    $this->objMailer = new PHPMailer(true);

    $this->objMailer->SMTPDebug = 2;
    $this->objMailer->isSMTP();
    $this->objMailer->Host = "smtp.gmail.com";
    $this->objMailer->SMTPAuth = true;
    $this->objMailer->Username = "myemail";
    $this->objMailer->Password = "mypass";
    $this->objMailer->SMTPSecure = 'tls';   
    $this->objMailer->Port = 587;


    //$this->objMailer->IsHTML(true);
    $this->objMailer->setFrom("myemail", "text");
    $this->objMailer->addReplyTo("myemail", "text");

}

I implement the other methods fine, problem is it worked before when i made test on localhost now it returns this message:

2017-11-30 17:50:29 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP m78sm953943vke.14 - gsmtp
2017-11-30 17:50:29 CLIENT -> SERVER: EHLO localhost
2017-11-30 17:50:29 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [200.113.200.2]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
2017-11-30 17:50:29 CLIENT -> SERVER: STARTTLS
2017-11-30 17:50:30 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
SMTP Error: Could not connect to SMTP host.
2017-11-30 17:50:30 CLIENT -> SERVER: QUIT
2017-11-30 17:50:31
2017-11-30 17:50:31
SMTP Error: Could not connect to SMTP host.

Fatal error: Uncaught PHPMailer\PHPMailer\Exception: SMTP Error: Could not connect to SMTP host. in C:\xampp\htdocs\haitopp\classes\vendor\phpmailer\phpmailer\src\PHPMailer.php:1882 Stack trace: #0 C:\xampp\htdocs\haitopp\classes\vendor\phpmailer\phpmailer\src\PHPMailer.php(1709): PHPMailer\PHPMailer\PHPMailer->smtpConnect(Array) #1 C:\xampp\htdocs\haitopp\classes\vendor\phpmailer\phpmailer\src\PHPMailer.php(1465): PHPMailer\PHPMailer\PHPMailer->smtpSend('Date: Thu, 30 N...', 'This is a multi...') #2 C:\xampp\htdocs\haitopp\classes\vendor\phpmailer\phpmailer\src\PHPMailer.php(1307): PHPMailer\PHPMailer\PHPMailer->postSend() #3 C:\xampp\htdocs\haitopp\classes\Email.php(62): PHPMailer\PHPMailer\PHPMailer->send() #4 C:\xampp\htdocs\haitopp\classes\User.php(34): Email->process(1, Array) #5 C:\xampp\htdocs\haitopppages\signup.php(96): User->addUser(Array, 'F@ckemall0') #6 C:\xampp\htdocs\haitopp\classes\Core.php(7): require_once('C:\xampp\htdocs...') #7 C:\xampp\htdocs\haitopp\index.php(6): Core->run() #8 {main} thrown in C:\xampp\htdocs\haitopp\classes\vendor\phpmailer\phpmailer\src\PHPMailer.php on line 1882

I read the troubleshooting but I still stuck, please help me with your guidance.

Most helpful comment

It looks like you have some duplicate rows in your __construct(). For example:

    $this->objMailer = new PHPMailer(true);
    $this->objMailer->SMTPDebug = 2;
    $this->objMailer->isSMTP();
    $this->objMailer->Host = "smtp.gmail.com";
    $this->objMailer->SMTPAuth = true;

鈥ll appears twice. Then the row:

$this->objMailer->Username = "

鈥s a syntax error. I believe this might be some copy-paste problem.

Anyway, please check phpinfo(); if you have extension=php_openssl.dll enabled.

All 3 comments

It looks like you have some duplicate rows in your __construct(). For example:

    $this->objMailer = new PHPMailer(true);
    $this->objMailer->SMTPDebug = 2;
    $this->objMailer->isSMTP();
    $this->objMailer->Host = "smtp.gmail.com";
    $this->objMailer->SMTPAuth = true;

鈥ll appears twice. Then the row:

$this->objMailer->Username = "

鈥s a syntax error. I believe this might be some copy-paste problem.

Anyway, please check phpinfo(); if you have extension=php_openssl.dll enabled.

You have a TLS problem. It's likely that your server is misconfigured (e.g. lacks openssl as @NiklasBr suggested, or has out of date CA certificates). Either way, you should read the troubleshooting guide that is linked from the error message as it tells you how to diagnose and deal with issues like this.

great!

Was this page helpful?
0 / 5 - 0 ratings