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