Ticket #530: jmailer.2.diff

File jmailer.2.diff, 4.5 kB (added by Lipki, 8 months ago)
  • jMailer.class.php

    old new  
    8686    public $Body               = ""; 
    8787 
    8888    /** 
     89     * Use tpl for sets the Body of the message.  This can be either an HTML or text body. 
     90     * If HTML then run IsHTML(true). 
     91     * @var string 
     92     */ 
     93    public $bodyTpl; 
     94 
     95    /** 
    8996     * Sets the text-only body of the message.  This automatically sets the 
    9097     * email to multipart/alternative.  This body can be read by mail 
    9198     * clients that do not have HTML email capability such as mutt. Clients 
     
    345352        $this->ReplyTo[$cur][0] = trim($address); 
    346353        $this->ReplyTo[$cur][1] = $name; 
    347354    } 
     355     
     356    function name_addr( $adresse, $type = 'addresse' ) { 
     357         
     358        if( strpos($adresse, '<') === true ) { 
     359            $tab = explode('>', $adresse); 
     360            $tab = explode('<', $tab[1]); 
     361            if( $type == 'addresse' && isset($tab[1]) ) return $tab[1]; 
     362            if( $type == 'name') return $tab[0]; 
     363        } 
     364        else if( $type == 'name' ) return ''; 
     365        else if( $type == 'addresse' ) return $adresse; 
     366         
     367    } 
    348368 
     369    /** 
     370     * Adds a Tpl référence. 
     371     * @param string $selector 
     372     * @return void 
     373     */ 
     374    function Tpl( $selector ) { 
     375         
     376        $this->bodyTpl = $selector; 
     377         
     378    } 
    349379 
    350380    ///////////////////////////////////////////////// 
    351381    // MAIL SENDING METHODS 
     
    361391        $header = ""; 
    362392        $body = ""; 
    363393        $result = true; 
     394         
     395        if( isset($this->bodyTpl) && $this->bodyTpl != "") { 
     396             
     397            $mailtpl = new jTpl(); 
     398            $metas = $mailtpl->meta( $this->bodyTpl ); 
     399             
     400            if( isset($metas['Subject']) ) 
     401                $this->Subject = $metas['Subject']; 
     402                 
     403            if( isset($metas['Priority']) ) 
     404                $this->Priority = $metas['Priority']; 
     405            $mailtpl->assign('Priority', $this->Priority ); 
     406                 
     407            if( isset($metas['From']) ) { 
     408                $this->From = $this->name_addr( $metas['From'], 'addresse' ); 
     409                $this->FromName = $this->name_addr( $metas['From'], 'name' ); 
     410            } 
     411            $mailtpl->assign('From', $this->From ); 
     412            $mailtpl->assign('FromName', $this->FromName ); 
     413             
     414            if( isset($metas['Sender']) ) 
     415                $this->Sender = $metas['Sender']; 
     416            $mailtpl->assign('Sender', $this->Sender ); 
     417             
     418            if( isset($metas['to']) ) 
     419                foreach( $metas['to'] as $val )  
     420                    $this->AddAddress($this->name_addr($val, 'addresse'), $this->name_addr($val, 'name')); 
     421            $mailtpl->assign('to', $this->to ); 
     422                     
     423            if( isset($metas['cc']) ) 
     424                foreach( $metas['cc'] as $val )  
     425                    $this->AddCC($this->name_addr($val, 'addresse'), $this->name_addr($val, 'name')); 
     426            $mailtpl->assign('cc', $this->cc ); 
     427                     
     428            if( isset($metas['bcc']) ) 
     429                foreach( $metas['bcc'] as $val )  
     430                    $this->AddBCC($this->name_addr($val, 'addresse'), $this->name_addr($val, 'name')); 
     431            $mailtpl->assign('bcc', $this->bcc ); 
     432                     
     433            if( isset($metas['ReplyTo']) ) 
     434                foreach( $metas['ReplyTo'] as $val )  
     435                    $this->AddReplyTo($this->name_addr($val, 'addresse'), $this->name_addr($val, 'name')); 
     436            $mailtpl->assign('ReplyTo', $this->ReplyTo ); 
     437             
     438            $this->Body = $mailtpl->fetch( $this->bodyTpl ); 
     439             
     440        } 
    364441 
    365442        if((count($this->to) + count($this->cc) + count($this->bcc)) < 1) 
    366443        { 
     
    445522            $rt = @mail($to, $this->EncodeHeader($this->Subject), $body, 
    446523                        $header, $params); 
    447524        } 
    448         else 
    449             $rt = @mail($to, $this->EncodeHeader($this->Subject), $body, $header); 
     525        else { 
     526            try { 
     527                $rt = mail($to, $this->EncodeHeader($this->Subject), $body, $header); 
     528            } catch ( Exeptions $e ) { 
     529                throw new jException('jelix~errors.mail.instantiate', $e->getMessage()); 
     530            } 
     531        } 
    450532 
    451533        if (isset($old_from)) 
    452534            ini_set("sendmail_from", $old_from); 
    453535 
    454         if(!$rt) 
    455         { 
    456             throw new jException('jelix~errors.mail.instantiate'); 
    457         } 
    458  
    459536        return true; 
    460537    } 
    461538 
Download in other formats: Original Format