php - PHPMailer: blocked by Strato hosting?

After having spent endless hours reading and trying different solutions, and checked the topics in StackOverflow related to PHPMailer, I am giving up... I hope someone could help me on this, I would really appreciate it.
I am using PHPMailer to send an automatic email when the user requests it via a form.
CASES
These are the different scenarios that I am facing:
A) From Localhost -> Everything works
- PHPMailer in Localhost sending an email from a gmail account (smtp.gmail.com) to the user -> WORKS
- Same, but from a hotmail account (smtp.live.com) -> WORKS
B) Exactly the same folders/files uploaded into my Strato hosting space:
- From the same gmail account that worked in the localhost -> The webpage freezes
- From the same hotmail account that worked in the localhost -> The webpage freezes
- From a Strato email account (smtp.strato.com) -> WORKS
When I say that the webpage freezes, I refer to the fact that the wepage keeps loading forever without showing any kind of error, despite having the option SMTPDebug = SMTP::DEBUG_SERVER activated, so that, it is very difficult to debug.
Actually, when that happens, the whole website gets irresponsive for (roughly) a couple of minutes.
ADDITIONAL INFO
PHP Version 7.3
PHPMailer Compatible with PHP >= 5.5
PHPMailer troubleshooting from GitHub-> I checked the whole list except the actions related to certificates, as I did not find the way to do it.
Stackoverflow -> I went through the whole list of PHPMailer-related topics. I did not find the solution.
Some especific actions that I tried suggested in the troubleshooting:
- Host = gethostbyname('smtp.gmail.com')
- I tried both PHPMailer::ENCRYPTION_STARTTLS and PHPMailer::ENCRYPTION_SMTPS
- Ports: 465 for ssl, 587 for tls, 25 and 2525.
- check that openssl extension is enabled
UPDATE 6th Oct 2020 Strato has clarified that they do not block these kind of requests, hence, the initial guess is not the cause.
Reasonable guess? This is telling me that Strato might be blocking my website from requesting to external servers, however, I am not a professional of this, so this is just a logical guess.
Many thanks to you all in advance. If I missed the solution somewhere, please do feel free to just redirct me to the article/site. Thanks!
CODE
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
ini_set('display_errors', true);
require_once '../vendor/PHPMailer/src/Exception.php';
require_once '../vendor/PHPMailer/src/PHPMailer.php';
require_once '../vendor/PHPMailer/src/SMTP.php';
if (extension_loaded('openssl')) {
echo 'openssl extension loaded.';}
$mail = new PHPMailer(true);
$mail->CharSet = "utf-8";
$mail->IsSMTP();
$mail->SMTPAutoTLS = false;
$mail->SMTPAuth = true;
$mail->Username='xxxxx';
$mail->Password = "xxxxx";
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
$mail->SMTPOptions = [
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
]
];
//$mail->Host = "smtp.strato.com";
//$mail->Host = gethostbyname('smtp.gmail.com');
$mail->Host = "smtp.gmail.com";
// set the SMTP port for the GMAIL server
$mail->Port = "587";
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
$mail->From='[email protected]';
$mail->FromName='xxxx';
$mail->AddAddress($email, '');
$mail->Subject = 'some text';
$mail->IsHTML(true);
$mail->Body = 'more text';
// *************************** The server hangs right here ***********************
if($mail->Send())
{
echo "nice";
}
else
{
echo "Mail Error - >".$mail->ErrorInfo;
}
?>
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: your lock file does not contain a compatible set of packages. please run composer update.
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.