Skip to content
Snippets Groups Projects
tgImap.class.php 1.75 KiB
Newer Older
  • Learn to ignore specific revisions
  • Ubbo Veentjer's avatar
    Ubbo Veentjer committed
    <?php
    
    
    require_once('Mail.php');
    require_once('Mail/mime.php');
    
    
    Ubbo Veentjer's avatar
    Ubbo Veentjer committed
    class tgImap {
    
      var $conf;
      var $sender;
      var $cc;
    
    
      function __construct( $conf) {    
    
    Ubbo Veentjer's avatar
    Ubbo Veentjer committed
        $this->conf = $conf;
    
        $this->sender = $conf['mail']['sender'];
        $this->cc = $conf['mail']['cc'];
    
        $params['host'] = $conf['mail']['smtpHost'];
        $params['username'] = $conf['mail']['smtpUser'];
        //$params['debug'] = true;
        $params['localhost'] = $conf['mail']['smtpEhlo'];
        $this->smtp =& Mail::factory('smtp', $params);
        
    
      function mail($to, $subject, $body, $cc=false) {
    /*
    
    Ubbo Veentjer's avatar
    Ubbo Veentjer committed
        // Falls eine Zeile der Nachricht mehr als 70 Zeichen enthälten könnte,
        // sollte wordwrap() benutzt werden (http://de.php.net/manual/de/function.mail.php)
        $body = wordwrap($body, 70);
        
        $header = 'From: '. $this->sender . "\n" .
                  'Reply-To: '. $this->sender . "\n" .
                  'Cc: ' . $this->cc . "\n" .
                  'X-Mailer: PHP/' . phpversion() . "\n" .
                  'MIME-Version: 1.0' . "\n" .
                  'Content-type: text/plain; charset=UTF-8' . "\n".
                  'Content-Transfer-Encoding: 8bit' . "\n";
    
        // replace linebreaks on www.textgrid.de
        $body = str_replace("\r\n", "\n", $body);
        
    
        mail($to, $subject, $body, $header);*/
        
        $text = $body;
        $html = '<html><body>'.nl2br($body).'</body></html>';
        $crlf = "\n";
    
        $mime = new Mail_mime(array('eol' => $crlf));
        $mime->setTXTBody($text);
        $mime->setHTMLBody($html);
    
        $headers['From']    = $this->sender;
        $headers['To']      = $to;
        $headers['Subject'] = $subject;
        
        if($cc) {
          $headers['Cc:']     = $this->cc;
        }
    
        $body = $mime->get();
        $headers = $mime->headers($headers);
        
        $this->smtp->send($to, $headers, $body);