Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHPMailer send email issues #1260

Closed
weirdeagle opened this issue Nov 30, 2017 · 3 comments
Closed

PHPMailer send email issues #1260

weirdeagle opened this issue Nov 30, 2017 · 3 comments

Comments

@weirdeagle
Copy link

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\haitopp\pages\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.

@NiklasBr
Copy link
Contributor

NiklasBr commented Dec 1, 2017

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;

…all appears twice. Then the row:

$this->objMailer->Username = "

…is a syntax error. I believe this might be some copy-paste problem.

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

@Synchro
Copy link
Member

Synchro commented Dec 1, 2017

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.

@Synchro Synchro closed this as completed Dec 1, 2017
@K4bl0-Skat3R
Copy link

great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants