26 private $sFromLibelle;
39 public function __construct(){
40 $this->sWall=
'afdsfdsfsqhghregregftervgqrdgregregfdgdfd';
44 public function setFrom($sFromLibelle,$sFrom){
46 $this->sFromLibelle=$sFromLibelle;
48 public function addTo($sTo){
49 $this->tTo[$sTo]=$sTo;
51 public function addCC($sCC){
52 $this->tCC[$sCC]=$sCC;
54 public function setBcc($sBCC){
58 public function setTitle($sTitle){
59 $this->sTitle=$sTitle;
61 public function setSubject($sTitle){
62 $this->sTitle=$sTitle;
64 public function setBody($sBody){
67 public function setBodyHtml($sBody){
68 $this->sBodyHtml=$sBody;
71 public function attachFile($sFile){
72 $this->sAttached=$sFile;
75 private function checkEmail($sEmail){
76 return preg_match(
'/^([a-zA-Z0-9\-\_\.]*)@([a-zA-Z0-9\-\_\.]*)\.([a-zA-Z]*)$/',$sEmail);
78 private function isValid(){
82 if($this->sFrom ==
''){
84 $tErrors[]=
"Pas d'email from";
85 }elseif(!$this->checkEmail($this->sFrom)){
87 $tErrors[]=
"Mauvais format pour l'email from (".$this->sFrom.
")";
90 if( count($this->tTo) == 0){
92 $tErrors[]=
"Pas d'email to";
94 foreach($this->tTo as $sTo){
95 if(!$this->checkEmail($sTo)){
97 $tErrors[]=
"Mauvais format pour l'email to (".$sTo.
")";
102 if($this->sTitle ==
''){
104 $tErrors[]=
"Pas de sujet";
109 $this->sErrors=
"Erreur plugin_mail lors de l envoi de l'email \n";
110 $this->sErrors.=implode(
"\n",$tErrors);
116 public function send(){
118 if(!$this->isValid()){
119 throw new Exception($this->sErrors);
128 $sHeader =
'From: "'.$this->sFromLibelle.
'" <'.$this->sFrom.
'>'.$n;
130 $sHeader .=
'Bcc: '.$this->sBCC.
"\r\n";
133 $sHeader .=
'Cc: '.implode(
',',$this->tCC).
"\r\n";
135 $sHeader .=
'Return-Path: <'.$this->sFrom.
'>'.$n;
136 $sHeader .=
'MIME-Version: 1.0'.$n;
137 $sHeader .=
'Content-Type: multipart/mixed; boundary="'.$this->sWall.
'"'.$rn;
141 if($this->sBody !=
''){
142 $sMsg .=
'--'.$this->sWall.$n;
143 $sMsg .=
'Content-Type: text/plain; charset="iso-8859-1"'.$nn;
144 $sMsg .= $this->sBody.$nn;
147 if($this->sBodyHtml !=
''){
148 $sMsg .=
'--'.$this->sWall.$n;
149 $sMsg .=
'Content-Type: text/html; charset="iso-8859-1"'.$nn;
150 $sMsg .= $this->sBodyHtml.$nn;
153 if($this->sAttached !=
''){
154 $sMsg .=
'--'.$this->sWall.
''.$n;
155 $sMsg .=
'Content-Type: text/csv; name="'.$this->sAttached.
'"'.$n;
156 $sMsg .=
'Content-Transfer-Encoding: base64'.$n;
157 $sMsg .=
'Content-Disposition:attachement; filename="'.$this->sAttached.
'"'.$nn;
158 $sMsg .= chunk_split(base64_encode(file_get_contents($this->sAttached))).
"\n";
161 if( mail( implode(
',',$this->tTo),$this->sTitle,$sMsg,$sHeader)){