Phpmailer: Hostgator is being a dick and blocks PHPmailer, but not other services, why?

Created on 11 Jan 2018  路  12Comments  路  Source: PHPMailer/PHPMailer

Hostgator is straightforward blocking PHPmailer with his domains.
The support said that they want that mail are used for spam.

I'm using swiftmailer and it works, but I don't understand why.
I like much more PHPmailer and I would seek a way to use it, but I tryed many things and failed so far :(

Most helpful comment

Just to let you know.
I am using hostgator shared server and have had no issue using ssl.
I used the 'simple example' from https://github.com/PHPMailer/PHPMailer
$mail->Host = 'gatorXXXX.hostgator.com';
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;

All 12 comments

As far as firewalls go, they can't tell the difference between PHPMailer and SwiftMailer - they both connect to SMTP servers in exactly the same way. If they are blocking SMTP and you're using that in PHPMailer and SwiftMailer is using php's mail() function (common in shared hosting), that would explain the difference. But without code, I can't tell.

Try change XMailer header with:
$mail->XMailer = 'MyMailer';
Maybe this will help 馃槇

That won't help if its not even connecting - it will never get as far as sending the X-Mailer header.

I don't know PHPmailer or Swiftmailer code (i'm not good enough to read into it). Or you were talking about my code?
The XMailer code part didn't do much.

Here's the code:

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

$myMail="[email protected]";
$toMail="[email protected]";
$myName="Mailer";
$toName="Andrea";




$mail = new PHPMailer(true);         
try {
    //Server settings
    $mail->isSMTP();         
    $mail->SMTPDebug = 2;     
    $mail->Host = 'mail.test.com'; //or IP
    $mail->SMTPAuth = true; 
    $mail->Username = '[email protected]'; 
    $mail->Password = 'password';       
    $mail->SMTPSecure = 'tls';  
    $mail->Port = 587;    //tryed this ports: 465  25   26

    $mail->setFrom('[email protected]', 'test');
    $mail->addAddress('[email protected]', 'John');

    $mail->isHTML(true);         
    $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.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
}

The code is fine - what debug output do you get? If none, set SMTPDebug = 3 for more connection-level info.

Sorry I don't know how to style it better.

I get this error:

2018-01-11 15:02:54 SERVER -> CLIENT: XXX-gatorXXXX.hostgator.com ESMTP Exim 4.89 #1 Thu, 11 Jan 2018 09:02:54 -0600 220-We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail.
2018-01-11 15:02:54 CLIENT -> SERVER: EHLO test.com
2018-01-11 15:02:54 SERVER -> CLIENT: XXX-gatorXXXX.hostgator.com Hello test.com [111.111.111]250-SIZE 52428800250-8BITMIME250-PIPELINING250-AUTH PLAIN LOGIN250-STARTTLS250 HELP
2018-01-11 15:02:54 CLIENT -> SERVER: STARTTLS
2018-01-11 15:02:54 SERVER -> CLIENT: 220 TLS go ahead
SMTP Error: Could not connect to SMTP host.
2018-01-11 15:02:54 CLIENT -> SERVER: QUIT
2018-01-11 15:02:54 SERVER -> CLIENT: 221 gatorXXXX.hostgator.com closing connection
SMTP Error: Could not connect to SMTP host.
Message could not be sent.Mailer Error: SMTP Error: Could not connect to SMTP host.

You have a TLS problem. It's likely your CA certificate bundle is out of date - look at the troubleshooting guide in the wiki for how to update that, and how to diagnose other TLS issues.

Try downgrading your encryption to SSL/465 instead.

What debug level are you using? I wonder if a higher level would give you more information.

(Aside: readers would probably prefer more professional titles here - Hostgator may not be a good host, but nevertheless, please keep titles succinct and useful).

The giveaway is that it gives up immediately after sending STARTTLS - that usually means that the cert is invalid, or you have outdated local CA certs so your validation fails. SMTPDebug = 3 might show more info - it's quite difficult to get at the low-level openssl messages in PHP - PRs welcome.

Switching to 'ssl' (SMTPS) probably won't help - the mail server will most likely use the same TLS stack for both, but you won't be able to see why it's failing in the SMTP transcript. Testing with the openssl client will be useful. Also I wouldn't call ssl/465 a downgrade - while it's been deprecated since 1998, it is more resistant to MITM attacks, and it's about to get a new lease of life in RFC8314.

Also I wouldn't call ssl/465 a downgrade - while it's been deprecated since 1998, it is more resistant to MITM attacks, and it's about to get a new lease of life in RFC8314.

@Synchro - aha, thanks, useful to know. I am writing an application to help users configure mail servers, and I've added guidance that TLS is to be preferred over SSL. I'll consider amending things accordingly!

Just to let you know.
I am using hostgator shared server and have had no issue using ssl.
I used the 'simple example' from https://github.com/PHPMailer/PHPMailer
$mail->Host = 'gatorXXXX.hostgator.com';
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;

Unfortunately that doesn't help much. The most likely explanation is that your local CA certs are out of date, so try updating them as described in the troubleshooting guide.

Was this page helpful?
0 / 5 - 0 ratings