Skip to content

Commit

Permalink
Increase timeout - fixes PHPMailer#104
Browse files Browse the repository at this point in the history
Improve debug options
  • Loading branch information
Synchro committed Sep 12, 2013
1 parent 8717a79 commit 3441a6d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# ChangeLog

* Increase timeout to match RFC2821 section 4.5.3.2 and thus not fail greetdelays, fixes #104
* Add timestamps to default debug output
* Add connection events and new level 3 to debug output options

## Version 5.2.7 (September 12th 2013)
* Add Ukranian translation from @Krezalis
* Support for do_verp
Expand Down
39 changes: 27 additions & 12 deletions class.smtp.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,12 @@ class SMTP

/**
* Debug output level.
* Options: 0 for no output, 1 for commands, 2 for data and commands
* Options:
* 0: no output
* 1: commands
* 2: data and commands
* 3: as 2 plus connection status
* 4: low level data output
* @type int
*/
public $do_debug = 0;
Expand All @@ -93,10 +98,11 @@ class SMTP
public $do_verp = false;

/**
* The SMTP timeout value for reads, in seconds.
* The timeout value for connection, in seconds.
* Default of 5 minutes (300sec) is from RFC2821 section 4.5.3.2
* @type int
*/
public $Timeout = 15;
public $Timeout = 300;

/**
* The SMTP timelimit value for reads, in seconds.
Expand Down Expand Up @@ -164,8 +170,7 @@ protected function edebug($str)
break;
case 'echo':
default:
//Just echoes whatever was received
echo $str;
echo gmdate('Y-m-d H:i:s')."\t".trim($str)."\n";
}
}

Expand Down Expand Up @@ -195,6 +200,10 @@ public function connect($host, $port = null, $timeout = 30, $options = array())
}

// Connect to the SMTP server
if ($this->do_debug >= 3) {
$this->edebug('Connection: opening');
}

$errno = 0;
$errstr = '';
$socket_context = stream_context_create($options);
Expand All @@ -217,12 +226,15 @@ public function connect($host, $port = null, $timeout = 30, $options = array())
);
if ($this->do_debug >= 1) {
$this->edebug(
'SMTP -> ERROR: ' . $this->error['error']
'SMTP ERROR: ' . $this->error['error']
. ": $errstr ($errno)"
);
}
return false;
}
if ($this->do_debug >= 3) {
$this->edebug('Connection: opened');
}

// SMTP server can take longer to respond, give longer timeout for first read
// Windows does not have support for this timeout function
Expand All @@ -238,7 +250,7 @@ public function connect($host, $port = null, $timeout = 30, $options = array())
$announce = $this->get_lines();

if ($this->do_debug >= 2) {
$this->edebug('SMTP -> FROM SERVER:' . $announce);
$this->edebug('SERVER -> CLIENT: ' . $announce);
}

return true;
Expand Down Expand Up @@ -437,7 +449,7 @@ public function connected()
// the socket is valid but we are not connected
if ($this->do_debug >= 1) {
$this->edebug(
'SMTP -> NOTICE: EOF caught while checking if connected'
'SMTP NOTICE: EOF caught while checking if connected'
);
}
$this->close();
Expand All @@ -462,6 +474,9 @@ public function close()
if (!empty($this->smtp_conn)) {
// close the connection and cleanup
fclose($this->smtp_conn);
if ($this->do_debug >= 3) {
$this->edebug('Connection: closed');
}
$this->smtp_conn = 0;
}
}
Expand Down Expand Up @@ -691,7 +706,7 @@ protected function sendCommand($command, $commandstring, $expect)
$code = substr($reply, 0, 3);

if ($this->do_debug >= 2) {
$this->edebug('SMTP -> FROM SERVER:' . $reply);
$this->edebug('SERVER -> CLIENT: ' . $reply);
}

if (!in_array($code, (array)$expect)) {
Expand All @@ -703,7 +718,7 @@ protected function sendCommand($command, $commandstring, $expect)
);
if ($this->do_debug >= 1) {
$this->edebug(
'SMTP -> ERROR: ' . $this->error['error'] . ': ' . $reply
'SMTP ERROR: ' . $this->error['error'] . ': ' . $reply
);
}
return false;
Expand Down Expand Up @@ -769,7 +784,7 @@ public function turn()
'error' => 'The SMTP TURN command is not implemented'
);
if ($this->do_debug >= 1) {
$this->edebug('SMTP -> NOTICE: ' . $this->error['error']);
$this->edebug('SMTP NOTICE: ' . $this->error['error']);
}
return false;
}
Expand All @@ -783,7 +798,7 @@ public function turn()
public function client_send($data)
{
if ($this->do_debug >= 1) {
$this->edebug("CLIENT -> SMTP: $data");
$this->edebug("CLIENT -> SERVER: $data");
}
return fwrite($this->smtp_conn, $data);
}
Expand Down

0 comments on commit 3441a6d

Please sign in to comment.