0

I am using PHPMailer on core PHP with Hostgator hosting business account and im getting the following error in SMTPDebug:

2020-01-13 13:16:54 SERVER -> CLIENT: 220-gator4001.hostgator.com ESMTP Exim 4.92 #2 Mon, 13 Jan 2020 07:16:54 -0600 220-We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail.
2020-01-13 13:16:54 CLIENT -> SERVER: EHLO www.domainname.com
2020-01-13 13:16:54 SERVER -> CLIENT: 250-gator4001.hostgator.com Hello www.domainname.com [192.185.16.229]250-SIZE 52428800250-8BITMIME250-PIPELINING250-AUTH PLAIN LOGIN250 HELP
2020-01-13 13:16:54 CLIENT -> SERVER: AUTH LOGIN
2020-01-13 13:16:54 SERVER -> CLIENT: 334 VXNlcm5hbWU6
2020-01-13 13:16:54 CLIENT -> SERVER: ZG9ub3RyZXBseUBjaGFpbnRoZWFwcC5jb20=
2020-01-13 13:16:54 SERVER -> CLIENT: 334 UGFzc3dvcmQ6
2020-01-13 13:16:54 CLIENT -> SERVER: YThoZkhON3FpKG9A
2020-01-13 13:16:54 SERVER -> CLIENT: 235 Authentication succeeded
2020-01-13 13:16:54 CLIENT -> SERVER: MAIL FROM:<donotreply@domainname.com>
2020-01-13 13:16:54 SERVER -> CLIENT: 250 OK
2020-01-13 13:16:54 CLIENT -> SERVER: RCPT TO:<my@emailaddress.com>
2020-01-13 13:16:54 SERVER -> CLIENT: 250 Accepted
2020-01-13 13:16:54 CLIENT -> SERVER: DATA
2020-01-13 13:16:54 SERVER -> CLIENT: 354 Enter message, ending with "." on a line by itself
2020-01-13 13:16:54 CLIENT -> SERVER: Date: Mon, 13 Jan 2020 16:16:54 +0300
2020-01-13 13:16:54 CLIENT -> SERVER: To: Taha Khan <my@emailaddress.com>
2020-01-13 13:16:54 CLIENT -> SERVER: From: Chain <donotreply@domainname.com>
2020-01-13 13:16:54 CLIENT -> SERVER: Subject: Chain account please activate your account
2020-01-13 13:16:54 CLIENT -> SERVER: Message-ID: <KvZPwFu2gMzFcs5f9XiBML51sazZsNQRXMqmxiuo@www.domainname.com>
2020-01-13 13:16:54 CLIENT -> SERVER: X-Mailer: PHPMailer 6.0.1 (https://github.com/PHPMailer/PHPMailer)
2020-01-13 13:16:54 CLIENT -> SERVER: MIME-Version: 1.0
2020-01-13 13:16:54 CLIENT -> SERVER: Content-Type: multipart/alternative;
2020-01-13 13:16:54 CLIENT -> SERVER: tboundary="b1_KvZPwFu2gMzFcs5f9XiBML51sazZsNQRXMqmxiuo"
2020-01-13 13:16:54 CLIENT -> SERVER: Content-Transfer-Encoding: 8bit
2020-01-13 13:16:54 CLIENT -> SERVER: 
2020-01-13 13:16:54 CLIENT -> SERVER: This is a multi-part message in MIME format.
2020-01-13 13:16:54 CLIENT -> SERVER: --b1_KvZPwFu2gMzFcs5f9XiBML51sazZsNQRXMqmxiuo
2020-01-13 13:16:54 CLIENT -> SERVER: Content-Type: text/plain; charset=us-ascii
2020-01-13 13:16:54 CLIENT -> SERVER: 
2020-01-13 13:16:54 CLIENT -> SERVER: This is a test html email
2020-01-13 13:16:54 CLIENT -> SERVER: 
2020-01-13 13:16:54 CLIENT -> SERVER: --b1_KvZPwFu2gMzFcs5f9XiBML51sazZsNQRXMqmxiuo
2020-01-13 13:16:54 CLIENT -> SERVER: Content-Type: text/html; charset=us-ascii
2020-01-13 13:16:54 CLIENT -> SERVER: 
2020-01-13 13:16:54 CLIENT -> SERVER: This is a test html email
2020-01-13 13:16:54 CLIENT -> SERVER: 
2020-01-13 13:16:54 CLIENT -> SERVER: 
2020-01-13 13:16:54 CLIENT -> SERVER: --b1_KvZPwFu2gMzFcs5f9XiBML51sazZsNQRXMqmxiuo--
2020-01-13 13:16:54 CLIENT -> SERVER: 
2020-01-13 13:16:54 CLIENT -> SERVER: .
2020-01-13 13:16:54 SERVER -> CLIENT: 250 OK id=1iqzaQ-000Ars-TL
2020-01-13 13:16:54 CLIENT -> SERVER: QUIT
2020-01-13 13:16:54 SERVER -> CLIENT: 221 gator4001.hostgator.com closing connection

the first line of the log says We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail. but at the same time PHPMailer is giving me response Mail sent.

What could be the issue here and how do i resolve it?

Also instead of my@emailaddress.com and domainname.com I've used my actual email address and actual website address. Just writing this here, apparently people point out the weirdest stuff here lol.

edit

Please find the php code below:

<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'Exception.php';
require 'PHPMailer.php';
require 'SMTP.php';


$mail = new PHPMailer(true);                              
try {
    //Server settings
    $mail->SMTPDebug = 2;
    $mail->isSMTP();
    $mail->Host = 'domainname.com';
    $mail->SMTPAuth = true;
    $mail->Username = 'donotreply@domainname.com';
    $mail->Password = 'mypassword';
    $mail->SMTPSecure = 'ssl';
    $mail->Port = 465;
    //Recipients
    $mail->setFrom('donotreply@domainname.com', 'MyTestEmail');
    $mail->addAddress('info@domainname.com', 'Khan');

    //Content
    $mail->isHTML(true);
    $mail->Subject = 'Test Email body';
    $mail->Body    = 'Test Email body';
    $mail->AltBody = 'Test Email body';

    $mail->send();
    return "SUCCESS";
} catch (Exception $e) {
    return "FAIL";
    // Use the line below to display error
    // echo 'Mailer Error: ' . $mail->ErrorInfo;
}   

?>

** UPDATE **

I've received bounced back email on donotreply@domainname.com with the following error:

The mail system

<info@domainname.com>: host mail.domainname.com[192.185.30.71] said:
    550-Verification failed for <donotreply@domainname.com> 550-No Such User
    Here 550 Sender verify failed (in reply to RCPT TO command)
Reporting-MTA: dns; gateway21.websitewelcome.com
X-Postfix-Queue-ID: 14259400E4AA1
X-Postfix-Sender: rfc822; donotreply@domainname.com
Arrival-Date: Mon, 13 Jan 2020 08:02:26 -0600 (CST)

Final-Recipient: rfc822; info@domainname.com
Original-Recipient: rfc822;info@domainname.com
Action: failed
Status: 5.0.0
Remote-MTA: dns; mail.domainname.com
Diagnostic-Code: smtp; 550-Verification failed for <donotreply@domainname.com>
    550-No Such User Here 550 Sender verify failed
Taha Khan
  • 164
  • 3
  • 16
  • Post your PHP CODE – Simone Rossaini Jan 13 '20 at 13:55
  • 1
    This "We do not..." message appears at the **start** of the log. i.e. **before** the mailserver has even received your email data. So at that moment, it has no idea whether you are attempting to send "bulk mail" or similar. It looks more like an announcement / warning than anything else. (bear in mind that, if you connected to the mailserver manually using telnet, you'd probably see that message on your screen). Does the email you sent get received at the other end (either in inbox or spam folder)? – ADyson Jan 13 '20 at 14:06
  • @ADyson I didnt receive the email anywhere ALTHOUGH the email i am using to send the email i.e donotreply@domainname.com; upon checking the inbox i've received multiple emails "Undelivered Mail Returned to Sender". At this point it seems like PHPMailer is working fine but gremlins are messing it up somewhere. – Taha Khan Jan 13 '20 at 14:19
  • Yes. Sending an email successfully is no guarantee that it will be delivered successfully. But it seems the issue isn't in your code, at least not directly. Do those messages give any specific reason why the mail is undelivered? Is the "to" email address correct? Maybe some other mailsever deemed it to be spam (or spam-like), perhaps? Could be lots of reasons. – ADyson Jan 13 '20 at 14:22
  • P.S. see this answer, especially from the section marked "Check spam folders; prevent emails from being flagged as spam" onwards, as it contains useful generic advice about making emails sent automatically from software more likely to be delivered successfully: https://stackoverflow.com/a/24644450/5947043 – ADyson Jan 13 '20 at 14:24
  • @ADyson First of all thank you for your active response. really appreciate your effort. I've updated the question with the error in the bounced email. – Taha Khan Jan 13 '20 at 14:29
  • 2
    That "*We do not authorize...*" message is purely informational, and is just the mail server's way of saying "hi"; it doesn't mean anything. The rest of your transcript shows an entirely successful delivery. There are no problems in this part of your code. Read [the deliverability notes in the project wiki](https://github.com/PHPMailer/PHPMailer/wiki/Improving-delivery-rates,-avoiding-spam-filters) for more info. – Synchro Jan 13 '20 at 14:34
  • @TahaKhan ok well "No Such User" seems clear enough. Note that it appears to be talking about the _sender_, not the recipient address. You did seem to be suggesting that this "donotreply" email address does in fact exist and have a usable inbox (presumably that's how you're seeing the bounce messages, unless you're using a forwarder of some sort). Can I guess perhaps that the PHP script you're sending from, or the mailserver you're connecting to in order to send (or both) is on a different domain from the email account itself? That's often a big red flag to a mail filter. – ADyson Jan 13 '20 at 14:40
  • P.S. are you able to send an email manually between these two addresses? Also, if you believe you've done everything correctly, it might be worth contacting the hosting company's support line. – ADyson Jan 13 '20 at 14:44
  • @ADyson Both sending and receiving emails are on separate domains but they are both hosted on hostgator. I sent email using webmail [from: donotreply - to: myemail] and even that got bounced. It seems like the email itself is not working. I am troubleshooting this from every possible way. Let me update you in a few moments. – Taha Khan Jan 13 '20 at 14:47
  • "I sent email using webmail [from: donotreply - to: myemail] and even that got bounced"... I suggest contacting hostgator then. If it fails when sending through their provided webmail interface, then it's clearly not a programming issue, so there's nothing further we can do to advise you here. – ADyson Jan 13 '20 at 14:54
  • Try replacing `$mail->SMTPSecure = "ssl"` to `$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;` or just `$mail->SMTPSecure = "tls"` – Jamie_D Jan 13 '20 at 14:54
  • *sigh* the problem was with sending email to this particular email. I contacted hostgator they told me they are facing issue with gateway21.websitewelcome.com and it has bad reputation for routing IP addresses. Email worked like a charm when i sent it to hotmail, gmail and other email addresses hosted on hostgator itself. They reason I opened this question here was that if you google for PHPMailer not working on hostgator, there are multiple posts which says that mail() function and swiftmail works fine but PHPMailer doesnt work with hostgator. i'll add my experience as answer here. – Taha Khan Jan 13 '20 at 14:58

1 Answers1

2

The issue was basically with the newly created email donotreply@domainname.com itself. The first two email addresses that were tested using PHPMailer bounced back in the inbox. If you are facing exactly the same issue as myself then i'd suggest you go through the following troubleshooting:

Make sure that Debug is not set to 0

$mail->SMTPDebug = 2

Test your code and check if PHPMailer is firing success at the end.

Check if PHPMailer echoes SUCCESS

As pointed out by @ADyson the following error/notice does not mean that the PHPMailer is not working.

SERVER -> CLIENT: 220-gator4001.hostgator.com ESMTP Exim 4.92 #2 Mon, 13 Jan 2020 07:16:54 -0600 220-We do not authorize the use of this system to transport unsolicited, 220 and/or bulk e-mail.

Secondly test your code by sending email to different domains on different servers

Test sending email to Gmail, Hotmail, Yahoo, Other Emails hosted on another server.

Check your inbox for any bounced back messages.

If you've received a bounced back message; It is certain that PHPMailer is working fine.

Contact your Host for more details by providing them with error details in the bounced email.

My issue was resolved by hostgator because the email to few email addresses would bounce back while it worked perfectly fine with Gmail and Hotmail

Taha Khan
  • 164
  • 3
  • 16