[ Index ]
 

Code source de Dotclear 2.0-beta6

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/inc/clearbricks/mail/ -> class.mail.php (source)

   1  <?php
   2  # ***** BEGIN LICENSE BLOCK *****
   3  # This file is part of Clearbricks.
   4  # Copyright (c) 2006 Olivier Meunier and contributors. All rights
   5  # reserved.
   6  #
   7  # Clearbricks is free software; you can redistribute it and/or modify
   8  # it under the terms of the GNU General Public License as published by
   9  # the Free Software Foundation; either version 2 of the License, or
  10  # (at your option) any later version.
  11  # 
  12  # Clearbricks is distributed in the hope that it will be useful,
  13  # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15  # GNU General Public License for more details.
  16  # 
  17  # You should have received a copy of the GNU General Public License
  18  # along with Clearbricks; if not, write to the Free Software
  19  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  20  #
  21  # ***** END LICENSE BLOCK *****
  22  
  23  class mail
  24  {
  25  	public static function sendMail($to,$subject,$message,$headers=null,$p=null)
  26      {
  27          $f = function_exists('_mail') ? '_mail' : null;
  28          
  29          if (is_array($headers)) {
  30              $headers = implode("\r\n",$headers);
  31          }
  32          
  33          if ($f == null)
  34          {
  35              if (!@mail($to,$subject,$message,$headers,$p)) {
  36                  throw new Exception('Unable to send email');
  37              }
  38          }
  39          else
  40          {
  41              call_user_func($f,$to,$subject,$message,$headers,$p);
  42          }
  43          
  44          return true;
  45      }
  46      
  47  	public static function getMX($host)
  48      {
  49          if (!getmxrr($host,$mx_h,$mx_w) || count($mx_h) == 0) {
  50              return false;
  51          }
  52          
  53          $res = array();
  54          
  55          for ($i=0; $i<count($mx_h); $i++) {
  56              $res[$mx_h[$i]] = $mx_w[$i];
  57          }
  58          
  59          asort($res);
  60          
  61          return $res;
  62      }
  63      
  64      /**
  65      @function QPHeader
  66      
  67      Encodes given string as a quoted printable mail header.
  68      
  69      @param str    string    String to encode
  70      @return string
  71      */
  72  	public static function QPHeader($str,$charset='UTF-8')
  73      {
  74          if (!preg_match('/[^\x00-\x3C\x3E-\x7E]/',$str)) {
  75              return $str;
  76          }
  77          
  78          return '=?'.$charset.'?Q?'.text::QPEncode($str).'?=';
  79      }
  80      
  81      /**
  82      @function B64Header
  83      
  84      Encodes given string as a base64 mail header.
  85      
  86      @param str    string    String to encode
  87      @return string
  88      */
  89  	public static function B64Header($str,$charset='UTF-8')
  90      {
  91          if (!preg_match('/[^\x00-\x3C\x3E-\x7E]/',$str)) {
  92              return $str;
  93          }
  94          
  95          return '=?'.$charset.'?B?'.base64_encode($str).'?=';
  96      }
  97  }
  98  ?>


Généré le : Fri Feb 23 22:16:06 2007 par Balluche grâce à PHPXref 0.7