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

Unable to send the email when TLS is enabled in PHP 5.5 version #2943

Closed
6 tasks
msrajawat298 opened this issue Aug 11, 2023 · 2 comments
Closed
6 tasks

Unable to send the email when TLS is enabled in PHP 5.5 version #2943

msrajawat298 opened this issue Aug 11, 2023 · 2 comments

Comments

@msrajawat298
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

Unable to send the email when TLS is enabled in PHP 5.5 version but the same thing is work in PHP 5.6.
Actually, our code base is very large so, we are not good to upgrade the PHP version for now.
Could you help us to resolve the issue, We have tried lots of but not gotten anything.
Currently, we are disabling the tools for email sending in php 5.5 env. but we need to use tls in the same env.
We are using send grid for mail sending. So we also discuss with SendGrid support they also told us we need to upgrade the php version or disable the tls.
Our single remaining chance is with you, and if you would help us, we'll be eternally thankful.

Code to reproduce

<?php
//Import PHPMailer classes into the global namespace
//These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;

//Load Composer's autoloader
require 'vendor/autoload.php';

echo (extension_loaded('openssl') ? 'SSL loaded' : 'SSL not loaded') . "<br/>";
//Create an instance; passing `true` enables exceptions
$mail = new PHPMailer(true);

try {
    //Server settings
    $mail->SMTPDebug = SMTP::DEBUG_SERVER;                      //Enable verbose debug output
    $mail->isSMTP();                                            //Send using SMTP
    $mail->Host = 'smtp.sendgrid.net';
    $mail->SMTPAuth   = true;                                   //Enable SMTP authentication
    $mail->Username = 'sendgriduser';
    $mail->Password = 'SG.secert';
    $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;            //Enable implicit TLS encryption
    $mail->Port       = 587;                                    //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
    $mail->SMTPDebug = 2;


    //Recipients
    $mail->setFrom('[email protected]', 'Mailer');
    $mail->addAddress('[email protected]', 'Joe User');     //Add a recipient

    //Content
    $mail->isHTML(true);                                  //Set email format to HTML
    $mail->Subject = 'Here is the subject';
    $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

    $mail->send();
    echo 'Message has been sent';
} catch (Exception $e) {
    echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}

Debug output

SSL loaded
2023-08-11 08:10:27 SERVER -> CLIENT: 220 SG ESMTP service ready at geopod-ismtpd-4
2023-08-11 08:10:27 CLIENT -> SERVER: EHLO localhost.localdomain
2023-08-11 08:10:27 SERVER -> CLIENT: 250-smtp.sendgrid.net250-8BITMIME250-PIPELINING250-SIZE 31457280250-STARTTLS250-AUTH PLAIN LOGIN250 AUTH=PLAIN LOGIN
2023-08-11 08:10:27 CLIENT -> SERVER: STARTTLS
2023-08-11 08:10:27 SERVER -> CLIENT: 220 Begin TLS negotiation now
SMTP Error: Could not connect to SMTP host.
2023-08-11 08:10:28 SMTP NOTICE: EOF caught while checking if connected
SMTP Error: Could not connect to SMTP host.
Message could not be sent. Mailer Error: SMTP Error: Could not connect to SMTP host.SMTP server error: Called QUIT without being connected
Screenshot 2023-08-11 at 1 48 52 PM

@Synchro
Copy link
Member

Synchro commented Aug 11, 2023

Being stuck on PHP 5.5 isn't good! That this is occurring at the STARTTLS stage suggests you have a mismatch in capabilities between your PHP and your mail server. PHP 5.6 made some big changes to TLS support, including adding support for TLS 1.2, which might be a requirement of your mail server. If you set SMTPDebug = 4 you may find you get more detail about how & why TLS is failing. You should be able to test the TLS configuration of your mail server using tools like testssl.sh which may help you figure out what you need to target in your PHP config. It's likely you will be able to figure out a workaround by adjusting the settings in the SMTPOptions property, which lets you get at PHP's underlying SSL config (most commonly used for disabling certificate verification, but please don't do that :)).

Check the version of openssl that your PHP build uses. TLS 1.2 support was added in openssl 1.0.1, so check whether you have that (in phpinfo()). If not, you can probably rebuild your PHP binary using a later version of openssl, because on the whole PHP's openssl support is handed off to the library, and it should generally work with later versions.

@msrajawat298
Copy link
Author

Hi @Synchro ,
We will check on the possible solutions which you have mentioned.
Thanks for the quick response. Really appreciate it!

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