# Postfix - improper command pipelining after HELO



## Mayhem30 (Mar 5, 2013)

I'm using Postfix v2.9.5 and just noticed this in the maillog.


```
Mar  4 17:55:37 localhost postfix/smtpd[13928]: connect from localhost[127.0.0.1]
Mar  4 17:55:37 localhost postfix/smtpd[13928]: improper command pipelining after HELO from localhost[127.0.0.1]: MAIL FROM: <support@example.com>\r\nRCPT TO: <****@gmail.com>\r\nDATA\r\nTo: ****@gmail.com
Mar  4 17:55:37 localhost postfix/smtpd[13928]: 7F0B345018: client=localhost[127.0.0.1]
Mar  4 17:55:37 localhost postfix/smtpd[13928]: lost connection after QUIT from localhost[127.0.0.1]
Mar  4 17:55:37 localhost postfix/smtpd[13928]: disconnect from localhost[127.0.0.1]
```

What is triggering this is a php mail script I'm using to keep clients updated.


```
$smtpServer = "localhost";
$localhost = "127.0.0.1";
$port = "25";
$timeout = "45";
$newLine = "\r\n";
$from = "support@example.com";

$smtpConnect = fsockopen($smtpServer, $port, $errno, $errstr, $timeout);
fputs($smtpConnect, "HELO $localhost". $newLine);
fputs($smtpConnect, "MAIL FROM: <$from>" . $newLine);
fputs($smtpConnect, "RCPT TO: <$Email>" . $newLine);
fputs($smtpConnect, "DATA" . $newLine);

$subj  = "Weekly Newsletter";
$mesg .= "Here is what's been happening this past week :\n\n";
$mesg .= "Then my newsletter info goes here ...\n\n";

$headers = "MIME-Version: 1.0" . $newLine;
$headers .= "Content-type: text/plain; charset=iso-8859-1" . $newLine;

fputs($smtpConnect, "To: $Email\r\nFrom: $from\r\nSubject: $subj\r\n$headers\r\n\r\n$mesg\r\n.\r\n");
fputs($smtpConnect,"QUIT" . $newLine);

fclose($smtpConnect);
```

I'm not sure if it's a problem with my php script - or a postfix setting.

Any ideas?


----------



## gordon@ (Mar 5, 2013)

You aren't waiting for the server responses. You aren't even checking the server responses. Use a mail library, don't write your own.


----------



## bkouhi (Mar 5, 2013)

Is there any special reason that you don't use mail/php5-imap?

```
$user = "me";
$pass = "nicepass";

$mbox = imap_open('{127.0.0.1:143/imap}', $user, $pass);
$to = $_POST["to"];
$subject = $_POST["subject"];
$cc = $_POST["cc"];
$bcc = $_POST["bcc"];
$body = $_POST["message"];

if ( imap_mail($to, $subject, $body,'' , $cc, $bcc) )
	echo "Your message was sent";
else
	echo "There was a problem while sending message";

imap_close($mbox);
```

This requires an IMAP server but you can use this.


----------



## Carpetsmoker (Mar 5, 2013)

> Is there any special reason that you don't use mail/php5-imap?



I don't know the quality of the imap_mail() function as such, I do know that:

- imap_mail() sends mail with SMTP, an IMAP library is a strange place for it to live
- The PHP imap library isn't particularly good in general
- This seems like an `afterthought function', not a core part of the library
- The PHP standard library is not exactly known for `getting it right'

In other words: one might question the quality of the imap_mail() function ...



> This requires an IMAP server but you can use this.


Note there are also many problems associated with the standard PHP mail() function, an obvious defect is that it's insecure unless you know what you're doing.
I would not recommend using it.

In any case, not rolling your own SMTP library is the best answer.
Swift Mailer is an excellent SMTP library.


----------



## bkouhi (Mar 5, 2013)

Thanks for your useful information. I'm just a beginner web developer.


----------



## Anonymous (Mar 5, 2013)

Mayhem30 said:
			
		

> ```
> ...
> fputs($smtpConnect, "HELO $localhost". $newLine);
> ...
> ```



For postfix allowing pipelining, you need to initiate the session using EHLO.

```
...
fputs($smtpConnect, "EHLO $localhost". $newLine);
...
```
In addition, you also need to check that the directive reject_unauth_pipelining is not active for the local connection.

Anyway, at one point in time, your code should read the response of postfix and act accordingly.


----------



## Mayhem30 (Mar 5, 2013)

Which is a better SMTP library? PHP Mailer or Swift Mailer?


----------



## Carpetsmoker (Mar 5, 2013)

Mayhem30 said:
			
		

> Which is a better SMTP library? PHP Mailer or Swift Mailer ?



The last update to PHPMailer is from 2009. Swift mailer is still being updated (last update: January 2013). Based on this alone, I would choose Swift mailer.


----------



## Mayhem30 (Mar 5, 2013)

Carpetsmoker said:
			
		

> The last update to PHPMailer is from 2009. Swift mailer is still being updated (last update: January 2013). Based on this alone, I would choose Swift mailer.



The version I have is: Version 5.2.4 (February 19, 2013)


----------



## Carpetsmoker (Mar 5, 2013)

Mayhem30 said:
			
		

> The version I have is : Version 5.2.4 (February 19, 2013)



Ah, In my stupidity I clicked the `download' link on the PHPMailer site, this only has outdated downloads, the newer downloads are available at Google code 
In that case, use whatever you prefer.


----------

