PHPMailer gives error “DATA END command failed” an

2019-08-16 21:02发布

问题:

I have tried to send email with this code (SMTP_HOST etc. are constants defined in config, they are all defined, it uses port 587):

    $txt = strip_tags(str_replace(array("<br>","<br\>","<br \>"),"\n",$this->_params['message']));
    // some irrelevant code here (saves record)
    $mail = new PHPMailer;
    $mail->isSMTP();
    $mail->Host = SMTP_HOST;
    $mail->Port = SMTP_PORT;
    $mail->SMTPAuth = true;
    $mail->Username = $mail->From = SMTP_USER;
    $mail->Password = SMTP_PASS;
    $mail->addReplyTo($this->_params['email'], $this->_params['name']);
    $mail->From = MAIL_FROM;
    $mail->FromName = MAIL_FROM_NAME;
    $mail->addAddress(MAIL_TO);
    $mail->Body = str_replace("\n","<br/>\n",$this->_params['message']);
    $mail->AltBody = $txt;
    $mail->Subject = MAIL_SUBJECT.$this->_params['subject'];
    $mail->isHTML (true);
    $mail->SMTPDebug = 3;
    $ok = $mail->send();

With PHPMailer version 5.2.7.

Debug info that I receive (I **** any private data):

2014-07-04 13:57:38 Connection: opening
2014-07-04 13:57:38 Connection: opened
2014-07-04 13:57:38 SERVER -> CLIENT: 220 **** ESMTP Exim 4.82 Fri, 04  Jul 2014 15:57:38 +0200
2014-07-04 13:57:38 CLIENT -> SERVER: EHLO ****
2014-07-04 13:57:38 SERVER -> CLIENT: 250-**** Hello **** [****]
250-SIZE 20971520
250-8BITMIME
250-PIPELINING
250-AUTH PLAIN LOGIN
250-STARTTLS
250 HELP
2014-07-04 13:57:38 CLIENT -> SERVER: AUTH LOGIN
2014-07-04 13:57:38 SERVER -> CLIENT: 334 ****
2014-07-04 13:57:38 CLIENT -> SERVER: ****
2014-07-04 13:57:38 SERVER -> CLIENT: 334 ****
2014-07-04 13:57:38 CLIENT -> SERVER: ****
2014-07-04 13:57:38 SERVER -> CLIENT: 235 Authentication succeeded
2014-07-04 13:57:38 CLIENT -> SERVER: MAIL FROM:<****>
2014-07-04 13:57:38 SERVER -> CLIENT: 250 OK
2014-07-04 13:57:38 CLIENT -> SERVER: RCPT TO:<****>
2014-07-04 13:57:38 SERVER -> CLIENT: 250 Accepted
2014-07-04 13:57:38 CLIENT -> SERVER: DATA
2014-07-04 13:57:38 SERVER -> CLIENT: 354 Enter message, ending with "." on a line by itself
2014-07-04 13:57:38 CLIENT -> SERVER: Date: Fri, 4 Jul 2014 15:57:38 +0200
2014-07-04 13:57:38 CLIENT -> SERVER: To: ****
2014-07-04 13:57:38 CLIENT -> SERVER: From: Automat SNC <****>
2014-07-04 13:57:38 CLIENT -> SERVER: Reply-To: **** <****@koszmail.pl>
2014-07-04 13:57:38 CLIENT -> SERVER: Subject: ****: Contact-form Test test test
2014-07-04 13:57:38 CLIENT -> SERVER: Message-ID: <ff1fbff844bf01ff24f5575e9e362ef1@****>
2014-07-04 13:57:38 CLIENT -> SERVER: X-Priority: 3
2014-07-04 13:57:38 CLIENT -> SERVER: X-Mailer: PHPMailer 5.2.7(https://github.com/PHPMailer/PHPMailer/)
2014-07-04 13:57:38 CLIENT -> SERVER: MIME-Version: 1.0
2014-07-04 13:57:38 CLIENT -> SERVER: Content-Type: multipart/alternative;
2014-07-04 13:57:38 CLIENT -> SERVER:   boundary="b1_ff1fbff844bf01ff24f5575e9e362ef1"
2014-07-04 13:57:38 CLIENT -> SERVER: Content-Transfer-Encoding: 8bit
2014-07-04 13:57:38 CLIENT -> SERVER:
2014-07-04 13:57:38 CLIENT -> SERVER: --b1_ff1fbff844bf01ff24f5575e9e362ef1
2014-07-04 13:57:38 CLIENT -> SERVER: Content-Type: text/plain; charset=us-ascii
2014-07-04 13:57:38 CLIENT -> SERVER:
2014-07-04 13:57:38 CLIENT -> SERVER: Test test test
2014-07-04 13:57:38 CLIENT -> SERVER: test test test test
2014-07-04 13:57:38 CLIENT -> SERVER: test
2014-07-04 13:57:38 CLIENT -> SERVER:
2014-07-04 13:57:38 CLIENT -> SERVER:
2014-07-04 13:57:38 CLIENT -> SERVER: --b1_ff1fbff844bf01ff24f5575e9e362ef1
2014-07-04 13:57:38 CLIENT -> SERVER: Content-Type: text/html; charset=us-ascii
2014-07-04 13:57:38 CLIENT -> SERVER:
2014-07-04 13:57:38 CLIENT -> SERVER: Test test test
2014-07-04 13:57:38 CLIENT -> SERVER: <br/>
2014-07-04 13:57:38 CLIENT -> SERVER: test test test test
2014-07-04 13:57:38 CLIENT -> SERVER: <br/>
2014-07-04 13:57:38 CLIENT -> SERVER: test
2014-07-04 13:57:38 CLIENT -> SERVER:
2014-07-04 13:57:38 CLIENT -> SERVER:
2014-07-04 13:57:38 CLIENT -> SERVER:
2014-07-04 13:57:38 CLIENT -> SERVER: --b1_ff1fbff844bf01ff24f5575e9e362ef1--
2014-07-04 13:57:38 CLIENT -> SERVER:
2014-07-04 13:57:38 CLIENT -> SERVER: .
2014-07-04 13:57:48 SERVER -> CLIENT:
2014-07-04 13:57:48 SMTP ERROR: DATA END command failed:
SMTP Error: data not accepted.
2014-07-04 13:57:48 CLIENT -> SERVER: QUIT
2014-07-04 13:57:49 SERVER -> CLIENT: 250 OK id=1X33ze-0007GO-Nc
2014-07-04 13:57:49 SMTP ERROR: QUIT command failed: 250 OK id=1X33ze-0007GO-Nc
2014-07-04 13:57:49 Connection: closed

Can someone give me a hint what can be wrong here?

回答1:

This strange behavior of SMTP server was caused by mistake in DNS and server configuration.

We have few VPS servers and a subdomain of one domain on one of them (receiver R) is delegated to other one (sender S). By mistake there was an "A" entry on S for domain of R (wchich really is on other DNS). It was also wrongfully set with IP of S. And S was configured (by Direct Admin) to handle emails for that R's domain. Which it couldn't do as there are no appropriate mailboxes nor MX record in local DNS.

Turned off email handling for receiver domain by sender and removed wrong DNS entries and now it works.