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

Error message while email service is working #2820

Closed
6 tasks
sergiuRemes opened this issue Nov 3, 2022 · 1 comment
Closed
6 tasks

Error message while email service is working #2820

sergiuRemes opened this issue Nov 3, 2022 · 1 comment

Comments

@sergiuRemes
Copy link

Please check these things before submitting your issue:

  • Read the error message you're seeing - it often tells you what is wrong, and may contain useful links & instructions
  • Make sure you're using the latest version of PHPMailer
  • Check that your problem is not dealt with in the troubleshooting guide, especially if you're having problems connecting to Gmail or GoDaddy
  • Include sufficient code to reproduce your problem
  • If you're having an SMTP issue, include the debug output generated with SMTPDebug = 2 set
  • If you have a question about how to use PHPMailer (rather than reporting a bug in it), tag a question on Stack Overflow with phpmailer, but search first!

Problem description

  • My email service is working.
  • I get a 200 status code on the contact.php file after submiting the form.

But, in the response I am getting the above message:
"2022-11-03 12:50:34 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP z23-20020a1c4c17000000b003b31c560a0csm1168771wmf.12 - gsmtp . . . "

And on the html page, under the form, I get (the whole message is here - same message in the response) this message as an error:

> Error: 2022-11-03 12:50:34 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP z23-20020a1c4c17000000b003b31c560a0csm1168771wmf.12 - gsmtp
> 2022-11-03 12:50:34 CLIENT -> SERVER: EHLO localhost
> 2022-11-03 12:50:34 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [2a00:23c8:3e80:dc01:59a6:9ff:97f:b70a]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
> 2022-11-03 12:50:34 CLIENT -> SERVER: STARTTLS
> 2022-11-03 12:50:34 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
> 2022-11-03 12:50:34 CLIENT -> SERVER: EHLO localhost
> 2022-11-03 12:50:34 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [2a00:23c8:3e80:dc01:59a6:9ff:97f:b70a]250-SIZE 35882577250-8BITMIME250-AUTH LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
> 2022-11-03 12:50:34 CLIENT -> SERVER: AUTH LOGIN
> 2022-11-03 12:50:34 SERVER -> CLIENT: 334 VXNlcm5hbWU6
> 2022-11-03 12:50:34 CLIENT -> SERVER: [credentials hidden]
> 2022-11-03 12:50:34 SERVER -> CLIENT: 334 UGFzc3dvcmQ6
> 2022-11-03 12:50:34 CLIENT -> SERVER: [credentials hidden]
> 2022-11-03 12:50:34 SERVER -> CLIENT: 235 2.7.0 Accepted
> 2022-11-03 12:50:34 CLIENT -> SERVER: MAIL FROM:<[email protected]>
> 2022-11-03 12:50:34 SERVER -> CLIENT: 250 2.1.0 OK z23-20020a1c4c17000000b003b31c560a0csm1168771wmf.12 - gsmtp
> 2022-11-03 12:50:34 CLIENT -> SERVER: RCPT TO:<[email protected]>
> 2022-11-03 12:50:34 SERVER -> CLIENT: 250 2.1.5 OK z23-20020a1c4c17000000b003b31c560a0csm1168771wmf.12 - gsmtp
> 2022-11-03 12:50:34 CLIENT -> SERVER: DATA
> 2022-11-03 12:50:35 SERVER -> CLIENT: 354 Go ahead z23-20020a1c4c17000000b003b31c560a0csm1168771wmf.12 - gsmtp
> 2022-11-03 12:50:35 CLIENT -> SERVER: Date: Thu, 3 Nov 2022 13:50:34 +0100
> 2022-11-03 12:50:35 CLIENT -> SERVER: To: [email protected]
> 2022-11-03 12:50:35 CLIENT -> SERVER: From: Mailer <[email protected]>
> 2022-11-03 12:50:35 CLIENT -> SERVER: Subject: Here is the subject
> 2022-11-03 12:50:35 CLIENT -> SERVER: Message-ID: <DdapHpSfH40ix3EOlf60U9544EaVxzEWtc7Ug8yfI@localhost>
> 2022-11-03 12:50:35 CLIENT -> SERVER: X-Mailer: PHPMailer 6.6.5 (https://github.com/PHPMailer/PHPMailer)
> 2022-11-03 12:50:35 CLIENT -> SERVER: MIME-Version: 1.0
> 2022-11-03 12:50:35 CLIENT -> SERVER: Content-Type: text/html; charset=iso-8859-1
> 2022-11-03 12:50:35 CLIENT -> SERVER:
> 2022-11-03 12:50:35 CLIENT -> SERVER: This is the HTML message body <b>in bold!</b>
> 2022-11-03 12:50:35 CLIENT -> SERVER:
> 2022-11-03 12:50:35 CLIENT -> SERVER: .
> 2022-11-03 12:50:35 SERVER -> CLIENT: 250 2.0.0 OK 1667479836 z23-20020a1c4c17000000b003b31c560a0csm1168771wmf.12 - gsmtp
> 2022-11-03 12:50:35 CLIENT -> SERVER: QUIT
> 2022-11-03 12:50:35 SERVER -> CLIENT: 221 2.0.0 closing connection z23-20020a1c4c17000000b003b31c560a0csm1168771wmf.12 - gsmtp
> Message sent

If I use $mail->SMTPDebug = 0; OR false; the message is:
> Error: Message sent

Code to reproduce

my contact.php file:

require 'C:/xampp/htdocs/sergiuremes.com/forms/vendor/phpmailer/src/PHPMailer.php';
require 'C:/xampp/htdocs/sergiuremes.com/forms/vendor/phpmailer/src/SMTP.php';
require 'C:/xampp/htdocs/sergiuremes.com/forms/vendor/phpmailer/src/Exception.php';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php';

$mail = new PHPMailer(true);
try {
    $mail->SMTPDebug = 2;                    
    $mail->isSMTP();                                          
    $mail->Host       = 'smtp.gmail.com';                    
    $mail->SMTPAuth   = true;                                   
    $mail->SMTPSecure = 'tls';             
    $mail->Port       = 587;                                   
    $mail->Username   =  //SMTP username                   
    $mail->Password   =  //SMTP password                        
    $mail->Subject = 'Here is the subject';
    $mail->setFrom(//SMTP username , 'Mailer');
    $mail->isHTML(true);                                 
    $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
    $mail->addAddress('[email protected]');       
    $mail->Send();
    
    echo "Message sent";     
         
 } catch (Exception $e) {
    echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
   }_
 

Debug output

Why do I get the error message?
How can it be fixed?

Many thanks!

@Synchro
Copy link
Member

Synchro commented Nov 3, 2022

It's not PHPMailer generating that "Error:" string – it must be something in your own code. You seems to be considering that any output at all is an error, which is not true.

Minor point - learn how to use composer properly. You're loading its autoloader, but short-circuiting it by loading PHPMailer's classes yourself, which you don't need to do if you're using composer.

@Synchro Synchro closed this as completed Nov 3, 2022
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

2 participants