Fix: Pb in error management
This commit is contained in:
parent
49d8233eb8
commit
c5effe4caf
@ -1,45 +1,45 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
class simplemail {
|
class simplemail {
|
||||||
|
|
||||||
var $recipientlist;
|
var $recipientlist;
|
||||||
var $subject;
|
var $subject;
|
||||||
var $hfrom;
|
var $hfrom;
|
||||||
var $hbcc;
|
var $hbcc;
|
||||||
var $hcc;
|
var $hcc;
|
||||||
var $deliveryreceipt;
|
var $deliveryreceipt;
|
||||||
|
|
||||||
var $Xsender;
|
var $Xsender;
|
||||||
var $ErrorsTo;
|
var $ErrorsTo;
|
||||||
var $XMailer = 'PHP';
|
var $XMailer = 'PHP';
|
||||||
var $XPriority = 3;
|
var $XPriority = 3;
|
||||||
|
|
||||||
var $set_mode='php';
|
var $set_mode='php';
|
||||||
|
|
||||||
var $text;
|
var $text;
|
||||||
var $html;
|
var $html;
|
||||||
var $attachement;
|
var $attachement;
|
||||||
var $htmlattachement;
|
var $htmlattachement;
|
||||||
|
|
||||||
var $recipient;
|
var $recipient;
|
||||||
|
|
||||||
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';
|
||||||
|
|
||||||
var $B1B = "----=_001";
|
var $B1B = "----=_001";
|
||||||
var $B2B = "----=_002";
|
var $B2B = "----=_002";
|
||||||
var $B3B = "----=_003";
|
var $B3B = "----=_003";
|
||||||
|
|
||||||
|
|
||||||
function simplemail() {
|
function simplemail() {
|
||||||
$this -> attachement = array();
|
$this -> attachement = array();
|
||||||
$this -> htmlattachement = array();
|
$this -> htmlattachement = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkaddress($address) {
|
function checkaddress($address) {
|
||||||
if ( preg_match('`([[:alnum:]]([-_.]?[[:alnum:]])*@[[:alnum:]]([-_.]?[[:alnum:]])*\.([a-z]{2,4}))`', $address) ) {
|
if ( preg_match('`([[:alnum:]]([-_.]?[[:alnum:]])*@[[:alnum:]]([-_.]?[[:alnum:]])*\.([a-z]{2,4}))`', $address) ) {
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@ -47,7 +47,7 @@ class simplemail {
|
|||||||
$this->error_log("l'adresse $address est invalide"); return FALSE;
|
$this->error_log("l'adresse $address est invalide"); return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkname($name) {
|
function checkname($name) {
|
||||||
if ( preg_match("`[0-9a-zA-Z\.\-_ ]*`" , $name ) ) {
|
if ( preg_match("`[0-9a-zA-Z\.\-_ ]*`" , $name ) ) {
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@ -55,21 +55,21 @@ class simplemail {
|
|||||||
$this->error_log(" le pseudo $name est invalide\n"); return FALSE;
|
$this->error_log(" le pseudo $name est invalide\n"); return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function makenameplusaddress($address,$name) {
|
function makenameplusaddress($address,$name) {
|
||||||
if ( !$this->checkaddress($address) ) return FALSE;
|
if ( !$this->checkaddress($address) ) return FALSE;
|
||||||
if ( !$this->checkname($name) ) return FALSE;
|
if ( !$this->checkname($name) ) return FALSE;
|
||||||
if ( empty($name) ) { return $address; }
|
if ( empty($name) ) { return $address; }
|
||||||
else { $tmp=$name." <".$address.">"; return $tmp; }
|
else { $tmp=$name." <".$address.">"; return $tmp; }
|
||||||
}
|
}
|
||||||
|
|
||||||
function addrecipient($newrecipient,$name='') {
|
function addrecipient($newrecipient,$name='') {
|
||||||
$tmp=$this->makenameplusaddress($newrecipient,$name);
|
$tmp=$this->makenameplusaddress($newrecipient,$name);
|
||||||
if ( !$tmp ) { $this->error_log(" To: error"); return FALSE; }
|
if ( !$tmp ) { $this->error_log(" To: error"); return FALSE; }
|
||||||
$this->recipientlist[] = array( 'mail'=>$newrecipient, 'nameplusmail' => $tmp );
|
$this->recipientlist[] = array( 'mail'=>$newrecipient, 'nameplusmail' => $tmp );
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
function addbcc($bcc,$name='') {
|
function addbcc($bcc,$name='') {
|
||||||
$tmp=$this->makenameplusaddress($bcc,$name);
|
$tmp=$this->makenameplusaddress($bcc,$name);
|
||||||
if ( !$tmp ) { $this->error_log(" Bcc: error"); return FALSE; }
|
if ( !$tmp ) { $this->error_log(" Bcc: error"); return FALSE; }
|
||||||
@ -77,7 +77,7 @@ class simplemail {
|
|||||||
$this->hbcc.= $tmp;
|
$this->hbcc.= $tmp;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
function addcc($cc,$name='') {
|
function addcc($cc,$name='') {
|
||||||
$tmp=$this->makenameplusaddress($cc,$name);
|
$tmp=$this->makenameplusaddress($cc,$name);
|
||||||
if ( !$tmp ) { $this->error_log(" Cc: error\n"); return FALSE; }
|
if ( !$tmp ) { $this->error_log(" Cc: error\n"); return FALSE; }
|
||||||
@ -85,32 +85,32 @@ class simplemail {
|
|||||||
$this->hcc.= $tmp;
|
$this->hcc.= $tmp;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
function addsubject($subject) {
|
function addsubject($subject) {
|
||||||
if (!empty($subject)) $this->subject = $subject;
|
if (!empty($subject)) $this->subject = $subject;
|
||||||
}
|
}
|
||||||
|
|
||||||
function addfrom($from,$name='') {
|
function addfrom($from,$name='') {
|
||||||
$tmp=$this->makenameplusaddress($from,$name);
|
$tmp=$this->makenameplusaddress($from,$name);
|
||||||
if ( !$tmp ) { $this->error_log(" From: error"); return FALSE; }
|
if ( !$tmp ) { $this->error_log(" From: error"); return FALSE; }
|
||||||
$this->hfrom = $tmp;
|
$this->hfrom = $tmp;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
function addreturnpath($return) {
|
function addreturnpath($return) {
|
||||||
$tmp=$this->makenameplusaddress($return,'');
|
$tmp=$this->makenameplusaddress($return,'');
|
||||||
if ( !$tmp ) { $this->error_log("Return-Path: error"); return FALSE; }
|
if ( !$tmp ) { $this->error_log("Return-Path: error"); return FALSE; }
|
||||||
$this->returnpath = $return;
|
$this->returnpath = $return;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
function addreplyto($replyto) {
|
function addreplyto($replyto) {
|
||||||
$tmp=$this->makenameplusaddress($replyto,'');
|
$tmp=$this->makenameplusaddress($replyto,'');
|
||||||
if ( !$tmp ) { $this->error_log(" Reply-To: error"); return FALSE; }
|
if ( !$tmp ) { $this->error_log(" Reply-To: error"); return FALSE; }
|
||||||
$this->returnpath = $tmp;
|
$this->returnpath = $tmp;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
function adddeliveryreceipt($deliveryreceipt) {
|
function adddeliveryreceipt($deliveryreceipt) {
|
||||||
$tmp=$this->makenameplusaddress($deliveryreceipt,'');
|
$tmp=$this->makenameplusaddress($deliveryreceipt,'');
|
||||||
if ( !$tmp ) { $this->error_log(" Disposition-Notification-To: error"); return FALSE; }
|
if ( !$tmp ) { $this->error_log(" Disposition-Notification-To: error"); return FALSE; }
|
||||||
@ -118,21 +118,21 @@ class simplemail {
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// les attachements
|
// les attachements
|
||||||
function addattachement($filename) {
|
function addattachement($filename) {
|
||||||
array_push ( $this -> attachement , array ( 'filename'=> $filename ) );
|
array_push ( $this -> attachement , array ( 'filename'=> $filename ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function writeattachement(&$attachement,$B) {
|
function writeattachement(&$attachement,$B) {
|
||||||
$message = '';
|
$message = '';
|
||||||
$inline = array();
|
$inline = array();
|
||||||
@ -140,12 +140,12 @@ class simplemail {
|
|||||||
foreach($attachement as $AttmFile){
|
foreach($attachement as $AttmFile){
|
||||||
$patharray = explode ("/", $AttmFile['filename']);
|
$patharray = explode ("/", $AttmFile['filename']);
|
||||||
$FileName = $patharray[count($patharray)-1];
|
$FileName = $patharray[count($patharray)-1];
|
||||||
|
|
||||||
// If duplicate images are embedded, they may show up as attachments, so remove them.
|
// If duplicate images are embedded, they may show up as attachments, so remove them.
|
||||||
if (!in_array($AttmFile['filename'],$inline))
|
if (!in_array($AttmFile['filename'],$inline))
|
||||||
{
|
{
|
||||||
$message .= "\n--".$B."\n";
|
$message .= "\n--".$B."\n";
|
||||||
|
|
||||||
if (!empty($AttmFile['cid'])) {
|
if (!empty($AttmFile['cid'])) {
|
||||||
$inline[] = $AttmFile['filename'];
|
$inline[] = $AttmFile['filename'];
|
||||||
$message .= "Content-Type: {$AttmFile['contenttype']};\n name=\"".$FileName."\"\n";
|
$message .= "Content-Type: {$AttmFile['contenttype']};\n name=\"".$FileName."\"\n";
|
||||||
@ -157,11 +157,11 @@ class simplemail {
|
|||||||
$message .= "Content-Transfer-Encoding: base64\n";
|
$message .= "Content-Transfer-Encoding: base64\n";
|
||||||
$message .= "Content-Disposition: attachment;\n filename=\"".$FileName."\"\n\n";
|
$message .= "Content-Disposition: attachment;\n filename=\"".$FileName."\"\n\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
$fd=fopen ($AttmFile['filename'], "rb");
|
$fd=fopen ($AttmFile['filename'], "rb");
|
||||||
$FileContent=fread($fd,filesize($AttmFile['filename']));
|
$FileContent=fread($fd,filesize($AttmFile['filename']));
|
||||||
fclose ($fd);
|
fclose ($fd);
|
||||||
|
|
||||||
$FileContent = chunk_split(base64_encode($FileContent));
|
$FileContent = chunk_split(base64_encode($FileContent));
|
||||||
$message .= $FileContent;
|
$message .= $FileContent;
|
||||||
$message .= "\n\n";
|
$message .= "\n\n";
|
||||||
@ -171,149 +171,149 @@ class simplemail {
|
|||||||
}
|
}
|
||||||
return $message;
|
return $message;
|
||||||
}
|
}
|
||||||
|
|
||||||
function BodyLineWrap($Value) {
|
function BodyLineWrap($Value) {
|
||||||
return wordwrap($Value, 78, "\n ");
|
return wordwrap($Value, 78, "\n ");
|
||||||
}
|
}
|
||||||
|
|
||||||
function makebody() {
|
function makebody() {
|
||||||
$message='';
|
$message='';
|
||||||
if ( !$this->html && $this->text && !empty($this->attachement) ) {
|
if ( !$this->html && $this->text && !empty($this->attachement) ) {
|
||||||
|
|
||||||
//Messages start with text/html alternatives in OB
|
//Messages start with text/html alternatives in OB
|
||||||
$message ="This is a multi-part message in MIME format.\n";
|
$message ="This is a multi-part message in MIME format.\n";
|
||||||
$message.="\n--".$this->B1B."\n";
|
$message.="\n--".$this->B1B."\n";
|
||||||
|
|
||||||
$message.="Content-Type: text/plain; charset=\"iso-8859-1\"\n";
|
$message.="Content-Type: text/plain; charset=\"iso-8859-1\"\n";
|
||||||
$message.="Content-Transfer-Encoding: quoted-printable\n\n";
|
$message.="Content-Transfer-Encoding: quoted-printable\n\n";
|
||||||
// plaintext goes here
|
// plaintext goes here
|
||||||
$message.=$this->BodyLineWrap($this->text)."\n\n";
|
$message.=$this->BodyLineWrap($this->text)."\n\n";
|
||||||
|
|
||||||
$message.=$this->writeattachement($this->attachement,$this->B1B);
|
$message.=$this->writeattachement($this->attachement,$this->B1B);
|
||||||
|
|
||||||
}
|
}
|
||||||
elseif ( !$this->html && $this->text && empty($this->attachement) ) {
|
elseif ( !$this->html && $this->text && empty($this->attachement) ) {
|
||||||
|
|
||||||
// plaintext goes here
|
// plaintext goes here
|
||||||
$message.=$this->BodyLineWrap($this->text)."\n\n";
|
$message.=$this->BodyLineWrap($this->text)."\n\n";
|
||||||
}
|
}
|
||||||
elseif ( $this->html ) {
|
elseif ( $this->html ) {
|
||||||
|
|
||||||
//Messages start with text/html alternatives in OB
|
//Messages start with text/html alternatives in OB
|
||||||
$message ="This is a multi-part message in MIME format.\n";
|
$message ="This is a multi-part message in MIME format.\n";
|
||||||
$message.="\n--".$this->B1B."\n";
|
$message.="\n--".$this->B1B."\n";
|
||||||
|
|
||||||
$message.="Content-Type: multipart/related;\n\t boundary=\"".$this->B2B."\"\n\n";
|
$message.="Content-Type: multipart/related;\n\t boundary=\"".$this->B2B."\"\n\n";
|
||||||
//plaintext section
|
//plaintext section
|
||||||
$message.="\n--".$this->B2B."\n";
|
$message.="\n--".$this->B2B."\n";
|
||||||
|
|
||||||
$message.="Content-Type: multipart/alternative;\n\t boundary=\"".$this->B3B."\"\n\n";
|
$message.="Content-Type: multipart/alternative;\n\t boundary=\"".$this->B3B."\"\n\n";
|
||||||
//plaintext section
|
//plaintext section
|
||||||
$message.="\n--".$this->B3B."\n";
|
$message.="\n--".$this->B3B."\n";
|
||||||
|
|
||||||
$message.="Content-Type: text/plain; charset=\"iso-8859-1\"\n";
|
$message.="Content-Type: text/plain; charset=\"iso-8859-1\"\n";
|
||||||
$message.="Content-Transfer-Encoding: quoted-printable\n\n";
|
$message.="Content-Transfer-Encoding: quoted-printable\n\n";
|
||||||
// plaintext goes here
|
// plaintext goes here
|
||||||
$message.=$this->BodyLineWrap($this->text)."\n\n";
|
$message.=$this->BodyLineWrap($this->text)."\n\n";
|
||||||
|
|
||||||
// html section
|
// html section
|
||||||
$message.="\n--".$this->B3B."\n";
|
$message.="\n--".$this->B3B."\n";
|
||||||
$message.="Content-Type: text/html; charset=\"iso-8859-1\"\n";
|
$message.="Content-Type: text/html; charset=\"iso-8859-1\"\n";
|
||||||
$message.="Content-Transfer-Encoding: base64\n\n";
|
$message.="Content-Transfer-Encoding: base64\n\n";
|
||||||
// html goes here
|
// html goes here
|
||||||
$message.=chunk_split(base64_encode($this->html))."\n\n";
|
$message.=chunk_split(base64_encode($this->html))."\n\n";
|
||||||
|
|
||||||
// end of text
|
// end of text
|
||||||
$message.="\n--".$this->B3B."--\n";
|
$message.="\n--".$this->B3B."--\n";
|
||||||
|
|
||||||
// attachments html
|
// attachments html
|
||||||
if (empty($this->htmlattachement)) {
|
if (empty($this->htmlattachement)) {
|
||||||
$message.="\n--".$this->B2B."--\n";
|
$message.="\n--".$this->B2B."--\n";
|
||||||
} else {
|
} else {
|
||||||
$message.=$this->writeattachement( $this->htmlattachement,$this->B2B);
|
$message.=$this->writeattachement( $this->htmlattachement,$this->B2B);
|
||||||
}
|
}
|
||||||
|
|
||||||
// attachments
|
// attachments
|
||||||
if (empty($this->attachement)) {
|
if (empty($this->attachement)) {
|
||||||
$message.="\n--".$this->B1B."--\n";
|
$message.="\n--".$this->B1B."--\n";
|
||||||
} else {
|
} else {
|
||||||
$message.=$this->writeattachement($this->attachement,$this->B1B);
|
$message.=$this->writeattachement($this->attachement,$this->B1B);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->body = $message;
|
$this->body = $message;
|
||||||
|
|
||||||
return $message;
|
return $message;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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) {
|
||||||
$this->headers .= $this->MakeHeaderField($Field,$Value);
|
$this->headers .= $this->MakeHeaderField($Field,$Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
function makeheader() {
|
function makeheader() {
|
||||||
|
|
||||||
$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");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
} else {
|
} else {
|
||||||
if ($this->set_mode!='php' ) {
|
if ($this->set_mode!='php' ) {
|
||||||
$this->AddField2Header("Subject", $this->subject);
|
$this->AddField2Header("Subject", $this->subject);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Date: Mon, 03 Nov 2003 20:48:06 +0100
|
# Date: Mon, 03 Nov 2003 20:48:06 +0100
|
||||||
$this->AddField2Header("Date", date ('r'));
|
$this->AddField2Header("Date", date ('r'));
|
||||||
|
|
||||||
if ( !empty($this->Xsender) ) { $this->AddField2Header("X-Sender",$this->Xsender); }
|
if ( !empty($this->Xsender) ) { $this->AddField2Header("X-Sender",$this->Xsender); }
|
||||||
else { $this->AddField2Header("X-Sender",$this->hfrom); }
|
else { $this->AddField2Header("X-Sender",$this->hfrom); }
|
||||||
|
|
||||||
if ( !empty($this->ErrorsTo) ) { $this->AddField2Header("Errors-To",$this->ErrorsTo); }
|
if ( !empty($this->ErrorsTo) ) { $this->AddField2Header("Errors-To",$this->ErrorsTo); }
|
||||||
else { $this->AddField2Header("Errors-To",$this->hfrom); }
|
else { $this->AddField2Header("Errors-To",$this->hfrom); }
|
||||||
|
|
||||||
if ( !empty($this->XMailer) ) $this->AddField2Header("X-Mailer",$this->XMailer);
|
if ( !empty($this->XMailer) ) $this->AddField2Header("X-Mailer",$this->XMailer);
|
||||||
|
|
||||||
if ( !empty($this->XPriority) ) $this->AddField2Header("X-Priority",$this->XPriority);
|
if ( !empty($this->XPriority) ) $this->AddField2Header("X-Priority",$this->XPriority);
|
||||||
|
|
||||||
if ( !empty($this->hfrom) ) $this->AddField2Header("From",$this->hfrom);
|
if ( !empty($this->hfrom) ) $this->AddField2Header("From",$this->hfrom);
|
||||||
|
|
||||||
if ( !empty($this->returnpath) ) $this->AddField2Header("Return-Path",$this->returnpath);
|
if ( !empty($this->returnpath) ) $this->AddField2Header("Return-Path",$this->returnpath);
|
||||||
|
|
||||||
if ( !empty($this->replyto) ) $this->AddField2Header("Reply-To",$this->replyto);
|
if ( !empty($this->replyto) ) $this->AddField2Header("Reply-To",$this->replyto);
|
||||||
|
|
||||||
if ( !empty($this->deliveryreceipt) ) $this->AddField2Header("Disposition-Notification-To",$this->deliveryreceipt);
|
if ( !empty($this->deliveryreceipt) ) $this->AddField2Header("Disposition-Notification-To",$this->deliveryreceipt);
|
||||||
|
|
||||||
$this->headers .="MIME-Version: 1.0\r\n";
|
$this->headers .="MIME-Version: 1.0\r\n";
|
||||||
|
|
||||||
if ( !$this->html && $this->text && !empty($this->attachement) ) {
|
if ( !$this->html && $this->text && !empty($this->attachement) ) {
|
||||||
$this->headers .= "Content-Type: multipart/mixed;\r\n\t boundary=\"".$this->B1B."\"\r\n";
|
$this->headers .= "Content-Type: multipart/mixed;\r\n\t boundary=\"".$this->B1B."\"\r\n";
|
||||||
} elseif ( !$this->html && $this->text && empty($this->attachement) ) {
|
} elseif ( !$this->html && $this->text && empty($this->attachement) ) {
|
||||||
$this->headers .="Content-Type: text/plain; charset=utf8; format=flowed\r\n";
|
$this->headers .="Content-Type: text/plain; charset=utf8; format=flowed\r\n";
|
||||||
$this->headers .="Content-Transfer-Encoding: 8bit\r\n";
|
$this->headers .="Content-Transfer-Encoding: 8bit\r\n";
|
||||||
} elseif ( $this->html ) {
|
} elseif ( $this->html ) {
|
||||||
if ( !$this->text ) { $this->text="HTML only!"; }
|
if ( !$this->text ) { $this->text="HTML only!"; }
|
||||||
$this->headers .="Content-Type: multipart/mixed;\r\n\t boundary=\"".$this->B1B."\"\r\n";
|
$this->headers .="Content-Type: multipart/mixed;\r\n\t boundary=\"".$this->B1B."\"\r\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !empty($this->hcc) ) $this->AddField2Header("Cc",$this->hcc);
|
if ( !empty($this->hcc) ) $this->AddField2Header("Cc",$this->hcc);
|
||||||
if ( !empty($this->hbcc) ) $this->AddField2Header("Bcc",$this->hbcc);
|
if ( !empty($this->hbcc) ) $this->AddField2Header("Bcc",$this->hbcc);
|
||||||
|
|
||||||
return $this->headers;
|
return $this->headers;
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendmail() {
|
function sendmail() {
|
||||||
$this->makebody();
|
$this->makebody();
|
||||||
$this->makeheader();
|
$this->makeheader();
|
||||||
@ -321,105 +321,111 @@ 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
|
||||||
|
|
||||||
function phpmail() {
|
function phpmail() {
|
||||||
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 !
|
||||||
} else {
|
//$this->error_log("envoie vers {$to['nameplusmail']} reussi");
|
||||||
$this->error_log("envoie vers {$to['nameplusmail']} echoué");
|
} else {
|
||||||
|
$this->error_log("envoie vers {$to['nameplusmail']} echoue");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Socket Function
|
|
||||||
|
|
||||||
function SocketStart() {
|
|
||||||
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;
|
|
||||||
};
|
|
||||||
return fgets($this->connect, 1024);
|
|
||||||
}
|
|
||||||
|
|
||||||
function SocketStop() {
|
|
||||||
fclose($this->connect);
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Socket Function
|
||||||
|
|
||||||
|
function SocketStart() {
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
return fgets($this->connect, 1024);
|
||||||
|
}
|
||||||
|
|
||||||
|
function SocketStop() {
|
||||||
|
fclose($this->connect);
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mail Socket
|
// Mail Socket
|
||||||
|
|
||||||
function socketmailstart() {
|
function socketmailstart() {
|
||||||
|
|
||||||
$this->SocketStart();
|
$this->SocketStart();
|
||||||
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" );
|
||||||
$this->SocketSend( "DATA\r\n" );
|
$this->SocketSend( "DATA\r\n" );
|
||||||
$this->SocketSend( $this->CleanMailDataString($this->headers)."\r\n", 'NOWAIT' );
|
$this->SocketSend( $this->CleanMailDataString($this->headers)."\r\n", 'NOWAIT' );
|
||||||
$this->SocketSend( $this->CleanMailDataString($this->body)."\r\n", 'NOWAIT' );
|
$this->SocketSend( $this->CleanMailDataString($this->body)."\r\n", 'NOWAIT' );
|
||||||
$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");
|
|
||||||
|
|
||||||
return TRUE;
|
// DOLCHANGE LDR To have no error when no error
|
||||||
}
|
//$this->error_log("Fin de l'envoi vers $to");
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user