Fix: Pb in error management

This commit is contained in:
Laurent Destailleur 2009-05-24 20:01:43 +00:00
parent 49d8233eb8
commit c5effe4caf

View File

@ -26,7 +26,7 @@ class simplemail {
var $body; var $body;
var $headers; var $headers;
var $error_log; var $error_log;
var $connect; var $connect;
var $default_charset = 'iso-8859-1'; var $default_charset = 'iso-8859-1';
@ -127,7 +127,7 @@ class simplemail {
// les attachements html // les attachements html
function addhtmlattachement($filename,$cid='',$contenttype='') { function addhtmlattachement($filename,$cid='',$contenttype='') {
array_push ( $this -> htmlattachement , array_push ( $this -> htmlattachement ,
array ( 'filename'=>$filename , array ( 'filename'=>$filename ,
'cid'=>$cid , 'cid'=>$cid ,
'contenttype'=>$contenttype ) 'contenttype'=>$contenttype )
); );
@ -251,7 +251,7 @@ class simplemail {
// Mail Headers Methods // Mail Headers Methods
function MakeHeaderField($Field,$Value) { function MakeHeaderField($Field,$Value) {
return wordwrap($Field.": ".$Value, 78, "\n ")."\r\n"; return wordwrap($Field.": ".$Value, 78, "\n ")."\r\n";
} }
function AddField2Header($Field,$Value) { function AddField2Header($Field,$Value) {
@ -263,7 +263,7 @@ class simplemail {
$this->headers = ''; $this->headers = '';
if ( empty($this->recipientlist) ) { $this->error_log("destinataire manquant"); return FALSE; } if ( empty($this->recipientlist) ) { $this->error_log("destinataire manquant"); return FALSE; }
// else { $this->AddField2Header("To",$this->recipient); } // else { $this->AddField2Header("To",$this->recipient); }
if ( empty($this->subject) ) { if ( empty($this->subject) ) {
$this->error_log("sujet manquant"); $this->error_log("sujet manquant");
@ -321,7 +321,9 @@ class simplemail {
case 'php' : $this->phpmail(); break; case 'php' : $this->phpmail(); break;
case 'socket': $this->socketmailloop(); break; case 'socket': $this->socketmailloop(); break;
} }
return TRUE;
// DOLCHANGE LDR
return (empty($this->error_log)?TRUE:FALSE);
} }
// Mail send by PHPmail // Mail send by PHPmail
@ -330,9 +332,10 @@ class simplemail {
while ( list($key, $to) = each($this->recipientlist) ) { while ( list($key, $to) = each($this->recipientlist) ) {
$this->recipient = $to['mail']; $this->recipient = $to['mail'];
if ( mail($to['mail'], $this->subject, $this->body, $this->makeheader() ) ) { if ( mail($to['mail'], $this->subject, $this->body, $this->makeheader() ) ) {
$this->error_log("envoie vers {$to['nameplusmail']} réussi"); // DOLCHANGE LDR Comment this to have no error when no error !
//$this->error_log("envoie vers {$to['nameplusmail']} reussi");
} else { } else {
$this->error_log("envoie vers {$to['nameplusmail']} echoué"); $this->error_log("envoie vers {$to['nameplusmail']} echoue");
} }
} }
return TRUE; return TRUE;
@ -342,19 +345,20 @@ class simplemail {
function SocketStart() { function SocketStart() {
if (!$this->connect = fsockopen (ini_get("SMTP"), ini_get("smtp_port"), $errno, $errstr, 30)) { if (!$this->connect = fsockopen (ini_get("SMTP"), ini_get("smtp_port"), $errno, $errstr, 30)) {
$this->error_log("Could not talk to the sendmail server!"); return FALSE; $this->error_log("Could not talk to the sendmail server!"); return FALSE;
}; };
return fgets($this->connect, 1024); return fgets($this->connect, 1024);
} }
function SocketStop() { function SocketStop() {
fclose($this->connect); fclose($this->connect);
return TRUE; return TRUE;
} }
function SocketSend($in,$wait='') { function SocketSend($in,$wait='') {
fputs($this->connect, $in, strlen($in)); fputs($this->connect, $in, strlen($in));
echo "-"; flush(); //echo $in;
//flush();
if(empty($wait)) { if(empty($wait)) {
$rcv = fgets($this->connect, 1024); $rcv = fgets($this->connect, 1024);
return $rcv; return $rcv;
@ -370,12 +374,13 @@ class simplemail {
if (!isset($_SERVER['SERVER_NAME']) || empty($_SERVER['SERVER_NAME'])) { $serv = 'unknown'; } if (!isset($_SERVER['SERVER_NAME']) || empty($_SERVER['SERVER_NAME'])) { $serv = 'unknown'; }
else { $serv = $_SERVER['SERVER_NAME']; } else { $serv = $_SERVER['SERVER_NAME']; }
$this->SocketSend("HELO $serv\r\n"); $this->SocketSend("HELO $serv\r\n");
} }
function socketmailsend($to) { function socketmailsend($to) {
$this->recipient = $to; $this->recipient = $to;
$this->error_log("Socket vers $to"); // DOLCHANGE LDR To have no error when no error
//$this->error_log("Socket vers $to");
$this->SocketSend( "MAIL FROM:{$this->hfrom}\r\n" ); $this->SocketSend( "MAIL FROM:{$this->hfrom}\r\n" );
$this->SocketSend( "RCPT TO:$to\r\n" ); $this->SocketSend( "RCPT TO:$to\r\n" );
@ -385,41 +390,42 @@ class simplemail {
$this->SocketSend( ".\r\n" ); $this->SocketSend( ".\r\n" );
$this->SocketSend( "RSET\r\n" ); $this->SocketSend( "RSET\r\n" );
$this->error_log("Fin de l'envoi vers $to"); // DOLCHANGE LDR To have no error when no error
//$this->error_log("Fin de l'envoi vers $to");
return TRUE;
}
function socketmailstop() {
$this->SocketSend("QUIT\r\n");
$this->SocketStop();
return TRUE; return TRUE;
} }
function socketmailloop() { function socketmailstop() {
$this->socketmailstart(); $this->SocketSend("QUIT\r\n");
while ( list($key, $to) = each($this->recipientlist)) { $this->SocketStop();
return TRUE;
}
function socketmailloop() {
$this->socketmailstart();
while ( list($key, $to) = each($this->recipientlist)) {
$this->recipient = $to['mail']; $this->recipient = $to['mail'];
$this->makeheader(); $this->makeheader();
$this->socketmailsend($to['mail']); $this->socketmailsend($to['mail']);
} }
$this->socketmailstop(); $this->socketmailstop();
} }
// Misc. // Misc.
function error_log($msg='') { function error_log($msg='') {
if(!empty($msg)) { if(!empty($msg)) {
$this->error_log .= $msg . "\r\n--\r\n"; $this->error_log .= $msg . "\r\n--\r\n";
return TRUE; return TRUE;
} }
return " --- Error Log --- \r\n\r\n".$this->error_log; return " --- Error Log --- \r\n\r\n".$this->error_log;
} }
function CleanMailDataString($data) { function CleanMailDataString($data) {
$data = preg_replace("/([^\r]{1})\n/", "\\1\r\n", $data); $data = preg_replace("/([^\r]{1})\n/", "\\1\r\n", $data);
$data = preg_replace("/\n\n/", "\n\r\n", $data); $data = preg_replace("/\n\n/", "\n\r\n", $data);
$data = preg_replace("/\n\./", "\n..", $data); $data = preg_replace("/\n\./", "\n..", $data);
return $data; return $data;
} }
} }