From: ("jkingsnorth")
Date:  22 Mar 2017 17:59:44 Hong Kong Time

[PEAR-BUG] Bug #20513 [Com]: Mail_smtp::send() doesn't close socket for smtp connection

NNTP-Posting-Host:  null

Edit report at

 ID:              20513
 Comment by:      jkingsnorth
 Reported By:     john at johnkingsnorth dot co dot uk
 Summary:         Mail_smtp::send() doesn't close socket for smtp
 Status:          Open
 Type:            Bug
 Package:         Mail
 Package Version: 1.2.0
 PHP Version:     5.4.33
 New Comment:

Confirmed the issue. Unfortunately there seems to be a patch attached to
this that doesn't exist any more?

Previous Comments:

[2015-03-09 11:20:09] e79ene

Added #patch bug:20513;patch:Fix-Bug-20513;revision:1425900009;.


[2015-03-08 15:33:50] e79ene

Mail::send() for smtp backend doesn't disconnect Net_Socket in 
case of error.

I use Mail::send() with smtp backend to send mails from php 
script on my FreeBSD server.
It works ok while there are no errors.
But if there's an error (E.g. SMTP authentication failure) 
Mail::send() finishes and leaves tcp connection with smtp server 
My script tried to send thousands of mails and thus Mail::send() 
opened thousands of socket connections and hit the system limit 
of open files. As a result other services (such as database) 
became unavailable too.

AFAIU the reason of the situation is in the source:

Mail_smtp::send() calls disconnect() in the end of function body 
in case of success. However the function contains plenty of error 
checks which perform return without call to disconnect().

Test script:
    'To' => '',
    'Subject' => 'Text message subject',

$mailer = Mail::factory('smtp', array(
    'host' => '',
    'auth' => true,
    'username' => '',
    'password' => 'the_password',

if (PEAR::isError($mailer))

$res = $mailer->send($headers['to'], $headers, 'Test messge body');

if ($res === true)
    echo "Mail sent.\n";
    echo "send() failed.\n";

if (isset($mailer->_smtp)) {
    echo "Socket status:\n";
} else
    echo "Connection closed.\n";

Expected result:
send() failed.
Connection closed.

Actual result:
send() failed.
Socket status:
    [stream_type] => tcp_socket
    [mode] => r+
    [unread_bytes] => 0
    [seekable] =>
    [timed_out] =>
    [blocked] => 1
    [eof] =>


Edit this bug report at