/[openfoncier]/trunk/obj/utils.class.php
ViewVC logotype

Diff of /trunk/obj/utils.class.php

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 516 by mlimic, Wed Oct 17 17:13:43 2012 UTC revision 531 by nhaye, Mon Oct 22 16:21:15 2012 UTC
# Line 492  class utils extends application { Line 492  class utils extends application {
492          }          }
493      }      }
494            
495        /**
496         * Envoie un mail avec piece jointe
497         *
498         * @param string $title Titre du mail
499         * @param string $message Corps du mail
500         * @param string $recipient Destinataire du mail
501         * @param array $file Destinataire du mail
502         * @access public
503         * @return bool True si le mail est correctement envoye, false sinon.
504         */
505        public function sendMail($title, $message, $recipient, $file = array()) {
506            
507            @include_once "../php/phpmailer/class.phpmailer.php";
508            
509            if (!class_exists("PHPMailer")) {
510                $this->addToLog("sendMail(): !class_exists(\"PHPMailer\")", DEBUG_MODE);
511                return false;
512            }
513    
514            //
515            $this->setMailConfig();
516            
517            //
518            if ($this->mail_config == false) {
519                $this->addToLog("sendMail(): aucune configuration mail", DEBUG_MODE);
520                return false;
521            }
522            
523            //
524            $mail = new PHPMailer(true);
525            
526            //
527            $mail->IsSMTP();
528            $mail->Username = $this->mail_config["mail_username"];
529            $mail->Password = $this->mail_config["mail_pass"];
530            if ($this->mail_config["mail_username"] == '') {
531                $mail->SMTPAuth = false;
532            } else {
533                $mail->SMTPAuth = true;
534            }
535            $mail->Port = $this->mail_config["mail_port"];
536            $mail->Host = $this->mail_config["mail_host"];
537            $mail->AddReplyTo($this->mail_config["mail_from"], $this->mail_config["mail_from_name"]);
538            $mail->From = $this->mail_config["mail_from"];
539            $mail->FromName = $this->mail_config["mail_from_name"];
540            foreach (explode(",",$recipient) as $adresse) {
541                if (!$this->checkValidEmailAddress($adresse)) {
542                    $this->addToLog("sendMail(): courriel incorrect ".$adresse, DEBUG_MODE);
543                    return false;
544                } else
545                    $mail->AddAddress(trim($adresse));
546            }
547            $mail->IsHTML(true);
548            
549            // Corps du message
550            $mail_body ="<html>";
551            $mail_body .= "<head><title>".$title."</title></head>";
552            $mail_body .= "<body>".$message."</body>";
553            $mail_body .= "</html>";
554            
555            $mail->Subject  = $title;
556            $mail->MsgHTML($mail_body);
557            foreach($file as $oneFile) {
558                
559                if($oneFile['stream']){
560                    $mail->AddStringAttachment($oneFile['content'], $oneFile['title'], $oneFile['encoding'] = 'base64',$oneFile['type'] = 'application/octet-stream');
561                } else{
562                    $mail->AddAttachment($oneFile['url']);
563                }
564            }
565            // Envoie de l'email
566            if ($mail->Send()) {
567                return true;
568            } else {
569                $this->addToLog("sendMail(): ".$mail->ErrorInfo, DEBUG_MODE);
570                return false;
571            }
572        }
573    
574  }  }
575    

Legend:
Removed from v.516  
changed lines
  Added in v.531

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26