smtp : update docComments
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@2724 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
74
smtp.php
74
smtp.php
@@ -6,33 +6,46 @@
|
||||
/** Allow to send mails by smtp */
|
||||
class smtp
|
||||
{
|
||||
/** Debug mode */
|
||||
/** Debug mode
|
||||
*/
|
||||
public $debug = 0;
|
||||
/** The debug file used to store all the communication between the client and
|
||||
* the server. The file contains the passwords if used ! */
|
||||
* the server. The file contains the passwords if used !
|
||||
*/
|
||||
public $debugFile = "/tmp/debugSMTP";
|
||||
/** The authentication user allow to send SMTP mails */
|
||||
/** The authentication user allow to send SMTP mails
|
||||
*/
|
||||
public $user = null;
|
||||
/** The authentication password allow to send SMTP mails */
|
||||
/** The authentication password allow to send SMTP mails
|
||||
*/
|
||||
public $password = null;
|
||||
/** The SMTP server name or IP */
|
||||
/** The SMTP server name or IP
|
||||
*/
|
||||
public $server = "127.0.0.1";
|
||||
/** The SMTP port */
|
||||
public $port = 25;
|
||||
/** The SMTPS support by tunnelling the session in SSL transport */
|
||||
/** The SMTP port
|
||||
*/
|
||||
public $port = false;
|
||||
/** The SMTPS support by tunnelling the session in SSL transport
|
||||
*/
|
||||
public $ssl = false;
|
||||
/** Check the certification chain in SSL mode */
|
||||
/** Check the certification chain in SSL mode
|
||||
*/
|
||||
public $sslCheck = true;
|
||||
/** The Timeout between the answer of the SMTP server. If the server don't
|
||||
* answer in this time, an exception is raised */
|
||||
* answer in this time, an exception is raised
|
||||
*/
|
||||
public $timeout = 10;
|
||||
/** Activate STARTTLS if needed. Allowed values : none, may, encrypt*/
|
||||
/** Activate STARTTLS if needed. Allowed values : none, may, encrypt
|
||||
*/
|
||||
public $starttls = "may";
|
||||
/** Check the certificate in STARTTLS */
|
||||
/** Check the certificate in STARTTLS
|
||||
*/
|
||||
public $starttlsCheck = false;
|
||||
/** The authentication methods in an array. Allowed : plain, login*/
|
||||
/** The authentication methods in an array. Allowed : plain, login
|
||||
*/
|
||||
public $authmethods = array ("plain", "login");
|
||||
/** The socket of the connection */
|
||||
/** The socket of the connection
|
||||
*/
|
||||
private $smtpStream = null;
|
||||
|
||||
/** Connect to the SMTP server */
|
||||
@@ -44,16 +57,23 @@ class smtp
|
||||
$this->server = "tls://$this->server";
|
||||
$context["ssl"]["verify_peer_name"] = $this->sslCheck;
|
||||
$context["ssl"]["verify_peer"] = $this->sslCheck;
|
||||
if ($this->port === false)
|
||||
$this->port = 465;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($this->port === false)
|
||||
$this->port = 25;
|
||||
}
|
||||
$mainContext = stream_context_create ($context);
|
||||
$this->debug ("####SMTP Connection to $this->server:$this->port (".
|
||||
date ("Y/m/d H:i:s").")\n");
|
||||
ini_set('track_errors', 1);
|
||||
ini_set('track_errors', 1);
|
||||
$this->smtpStream = @stream_socket_client ("$this->server:$this->port",
|
||||
$errno, $errstr,
|
||||
$this->timeout, STREAM_CLIENT_CONNECT,
|
||||
$mainContext);
|
||||
ini_set('track_errors', 0);
|
||||
ini_set('track_errors', 0);
|
||||
if ($this->smtpStream === false)
|
||||
{
|
||||
if ($errstr === "" && $php_errormsg !== "")
|
||||
@@ -78,7 +98,7 @@ class smtp
|
||||
stream_context_set_option ($this->smtpStream, $context);
|
||||
// The track_errors permit to create the $php_errormsg in case of
|
||||
// warning
|
||||
ini_set('track_errors', 1);
|
||||
ini_set('track_errors', 1);
|
||||
if (@stream_socket_enable_crypto ($this->smtpStream, true,
|
||||
STREAM_CRYPTO_METHOD_TLS_CLIENT) ===
|
||||
false)
|
||||
@@ -90,7 +110,7 @@ class smtp
|
||||
}
|
||||
elseif ($this->starttls === "encrypt")
|
||||
throw new \Exception (_("Server doesn't supports STARTTLS"), 500);
|
||||
|
||||
|
||||
if ($this->user !== null && $this->password !== null)
|
||||
{
|
||||
$auths = preg_grep ("#^250-AUTH #", $features);
|
||||
@@ -116,7 +136,7 @@ class smtp
|
||||
}
|
||||
}
|
||||
|
||||
/** Send the mail to the users
|
||||
/** Send the mail to the users
|
||||
* @param string $from The email address used for the from enveloppe
|
||||
* @param string|array $to the recipient of the email. Not displayed in the
|
||||
* email content
|
||||
@@ -141,7 +161,8 @@ class smtp
|
||||
return $this->putLine ("$completeMail.\r\n");
|
||||
}
|
||||
|
||||
/** Disconnect from the SMTP server */
|
||||
/** Disconnect from the SMTP server
|
||||
*/
|
||||
public function disconnect ()
|
||||
{
|
||||
if ($this->smtpStream === null)
|
||||
@@ -151,8 +172,9 @@ class smtp
|
||||
$this->putLine ("QUIT\r\n");
|
||||
fclose ($this->smtpStream);
|
||||
}
|
||||
|
||||
/** Reset the session to start a new mail in the same SMTP connection */
|
||||
|
||||
/** Reset the session to start a new mail in the same SMTP connection
|
||||
*/
|
||||
public function reset ()
|
||||
{
|
||||
if ($this->smtpStream === null)
|
||||
@@ -162,7 +184,8 @@ class smtp
|
||||
$this->putLine ("RSET\r\n");
|
||||
}
|
||||
|
||||
/** Send something to the SMTP server. Wait the acknoledgement line */
|
||||
/** Send something to the SMTP server. Wait the acknoledgement line
|
||||
*/
|
||||
private function putLine ($data)
|
||||
{
|
||||
$this->debug ("> $data");
|
||||
@@ -170,7 +193,8 @@ class smtp
|
||||
return $this->getLine ($data);
|
||||
}
|
||||
|
||||
/** Wait something from the server */
|
||||
/** Wait something from the server
|
||||
*/
|
||||
private function getLine ($message = "")
|
||||
{
|
||||
$this->debug ("Waiting for ".rtrim ($message)." answer\n", 2);
|
||||
@@ -199,6 +223,8 @@ class smtp
|
||||
return $content;
|
||||
}
|
||||
|
||||
/** Save the connection debug in file
|
||||
*/
|
||||
private function debug ($message, $priority = 1)
|
||||
{
|
||||
if ($this->debug == false)
|
||||
|
||||
Reference in New Issue
Block a user