PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Mail » Mail » Bug #8723

Missing trailing newline in headers with SMTP backend

Details

Submitted2006-09-17 14:45 UTC
Fromroychri at php dot net
Assignedchagenbu
StatusClosed
PackageMail
PHP Version4.4.0
OSAny
Roadmaps(Not assigned)

Comments

[2006-09-17 14:45 UTC] roychri at php dot net

Description:
------------
I recently upgraded Mail to version 1.1.13 and my scripts using Mail with the smtp backend started failing.
There is not enough newlines between the headers and the body anymore.
If I revert back to 1.1.10, I have no problems.

In the example I provided in this bug, I replaced actual email adresses by "x" to prevent spam.

I saw that the Mail/sendmail.php was changed (Revision 1.17) to provide two seperator ($this->sep) and I thought that the same would apply to Mail/smtp.php so I propose a patch (included in the text script section). This patch works for me.

Test script:
---------------
require_once("Mail.php");
$recipients = 'x';
$params = Array('host' => 'localhost', 'port' => 25, 'debug' => true);
$mail_object =& Mail::factory('smtp', $params);
$headers['From'] = 'x';
$headers['To'] = $recipients;
$headers['Subject'] = 'Test message';
header("Content-Type: text/plain");
$mail_object->send($recipients, $headers, $body = 'Test message');

========================================

--- Mail/smtp.php~ 2006-09-17 10:12:18.000000000 -0400
+++ Mail/smtp.php 2006-09-17 10:16:29.000000000 -0400
@@ -288,7 +288,8 @@
}

/* Send the message's headers and the body as SMTP data. */
- if (PEAR::isError($res = $this->_smtp->data("$textHeaders\r\n$body"))) {
+ $data = $textHeaders."\r\n\r\n".$body;
+ if (PEAR::isError($res = $this->_smtp->data($data))) {
$error = $this->_error('Failed to send data', $res);
$this->_smtp->rset();
return PEAR::raiseError($error, PEAR_MAIL_SMTP_ERROR_DATA);

Expected result:
----------------
DEBUG: Recv: 220 x ESMTP Sendmail 8.13.6/8.13.6; Sun, 17 Sep 2006 10:35:16 -0400
DEBUG: Send: EHLO localhost

DEBUG: Recv: 250-x Hello x [209.249.12.15], pleased to meet you
DEBUG: Send: MAIL FROM:<x>

DEBUG: Recv: 250 2.1.0 <x>... Sender ok
DEBUG: Send: RCPT TO:<x>

DEBUG: Recv: 250 2.1.5 <x>... Recipient ok
DEBUG: Send: DATA

DEBUG: Recv: 354 Enter mail, end with "." on a line by itself
DEBUG: Send: From: x
To: x
Subject: Test message

Test message
.

DEBUG: Recv: 250 2.0.0 k8HEZGSO004852 Message accepted for delivery
DEBUG: Send: QUIT

DEBUG: Recv: 221 2.0.0 x closing connection

Actual result:
--------------
DEBUG: Recv: 220 x ESMTP Sendmail 8.13.6/8.13.6; Sun, 17 Sep 2006 10:32:47 -0400
DEBUG: Send: EHLO localhost

DEBUG: Recv: 250-x Hello x [209.249.12.15], pleased to meet you
DEBUG: Send: MAIL FROM:<x>

DEBUG: Recv: 250 2.1.0 <x>... Sender ok
DEBUG: Send: RCPT TO:<x>

DEBUG: Recv: 250 2.1.5 <x>... Recipient ok
DEBUG: Send: DATA

DEBUG: Recv: 354 Enter mail, end with "." on a line by itself
DEBUG: Send: From: x
To: x
Subject: Test message
Test message
.

DEBUG: Recv: 250 2.0.0 k8HEWlqE003028 Message accepted for delivery
DEBUG: Send: QUIT

DEBUG: Recv: 221 2.0.0 x closing connection

[2006-09-26 13:10 UTC] jj at learnbit dot com

I have the same problem with version 1.1.13. The suggested patch (inserting "\r\n" between header and body) works for me.

[2006-09-30 04:19 UTC] tabacco at telltalegames dot com

I can verify this one as well. the proposed patch worked for me.

[2006-10-11 20:34 UTC] chagenbu at php dot net

Thank you for your bug report. This issue has been fixed
in the latest released version of the package, which you can download at
http://pear.php.net/get/Mail