Documentation TYPO3 par Ameos

class.t3lib_formmail.php

00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2006 Kasper Skaarhoj (kasperYYYY@typo3.com)
00006 *  All rights reserved
00007 *
00008 *  This script is part of the TYPO3 project. The TYPO3 project is
00009 *  free software; you can redistribute it and/or modify
00010 *  it under the terms of the GNU General Public License as published by
00011 *  the Free Software Foundation; either version 2 of the License, or
00012 *  (at your option) any later version.
00013 *
00014 *  The GNU General Public License can be found at
00015 *  http://www.gnu.org/copyleft/gpl.html.
00016 *  A copy is found in the textfile GPL.txt and important notices to the license
00017 *  from the author is found in LICENSE.txt distributed with these scripts.
00018 *
00019 *
00020 *  This script is distributed in the hope that it will be useful,
00021 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023 *  GNU General Public License for more details.
00024 *
00025 *  This copyright notice MUST APPEAR in all copies of the script!
00026 ***************************************************************/
00069 class t3lib_formmail extends t3lib_htmlmail {
00070         var $reserved_names = 'recipient,recipient_copy,auto_respond_msg,redirect,subject,attachment,from_email,from_name,replyto_email,replyto_name,organisation,priority,html_enabled,quoted_printable,submit_x,submit_y';
00071 
00072 
00095         function start($V,$base64=false)        {
00096                 parent::start();
00097 
00098                 if ($base64 || $V['use_base64'])        { $this->useBase64(); }
00099 
00100                 if ($GLOBALS['TSFE']->config['config']['formMailCharset'])      {       // Respect formMailCharset if it was set
00101                         $this->charset = trim($GLOBALS['TSFE']->config['config']['formMailCharset']);
00102                 }
00103 
00104                 if (isset($V['recipient']))     {
00105                                 // Sets the message id
00106                         $this->messageid = md5(microtime()).'@domain.tld';
00107 
00108                         $this->subject = ($V['subject']) ? $V['subject'] : 'Formmail on '.t3lib_div::getIndpEnv('HTTP_HOST');
00109                         $this->from_email = ($V['from_email']) ? $V['from_email'] : (($V['email'])?$V['email']:'');
00110                         $this->from_name = ($V['from_name']) ? $V['from_name'] : (($V['name'])?$V['name']:'');
00111                         $this->replyto_email = ($V['replyto_email']) ? $V['replyto_email'] : $this->from_email;
00112                         $this->replyto_name = ($V['replyto_name']) ? $V['replyto_name'] : $this->from_name;
00113                         $this->organisation = ($V['organisation']) ? $V['organisation'] : '';
00114                         $this->priority = ($V['priority']) ? t3lib_div::intInRange($V['priority'],1,5) : 3;
00115 
00116                                 // Auto responder.
00117                         $this->auto_respond_msg = (trim($V['auto_respond_msg']) && $this->from_email) ? trim($V['auto_respond_msg']) : '';
00118 
00119                         $Plain_content = '';
00120                         $HTML_content = '<table border="0" cellpadding="2" cellspacing="2">';
00121 
00122                                 // Runs through $V and generates the mail
00123                         if (is_array($V))       {
00124                                 reset($V);
00125                                 while (list($key,$val)=each($V))        {
00126                                         if (!t3lib_div::inList($this->reserved_names,$key))     {
00127                                                 $space = (strlen($val)>60)?chr(10):'';
00128                                                 $val = (is_array($val) ? implode($val,chr(10)) : $val);
00129                                                 $Plain_content.= strtoupper($key).':  '.$space.$val."\n".$space;
00130                                                 $HTML_content.='<tr><td bgcolor="#eeeeee"><font face="Verdana" size="1"><b>'.strtoupper($key).'</b></font></td><td bgcolor="#eeeeee"><font face="Verdana" size="1">'.nl2br(HTMLSpecialChars($val)).'&nbsp;</font></td></tr>';
00131                                         }
00132                                 }
00133                         }
00134                         $HTML_content.= '</table>';
00135 
00136 
00137                         if ($V['html_enabled']) {
00138                                 $this->setHTML($this->encodeMsg($HTML_content));
00139                         }
00140                         $this->addPlain($Plain_content);
00141 
00142                         for ($a=0;$a<10;$a++)   {
00143                                 $varname = 'attachment'.(($a)?$a:'');
00144                                 $theFile = t3lib_div::upload_to_tempfile($_FILES[$varname]['tmp_name']);
00145                                 $theName = $_FILES[$varname]['name'];
00146 
00147                                 if ($theFile && @file_exists($theFile)) {
00148                                         if (filesize($theFile) < 250000)        {
00149                                                 $this->addAttachment($theFile, $theName);
00150                                         }
00151                                 }
00152                                 t3lib_div::unlink_tempfile($theFile);
00153                         }
00154 
00155                         $this->setHeaders();
00156                         $this->setContent();
00157                         $this->setRecipient($V['recipient']);
00158                         if ($V['recipient_copy'])       {
00159                                 $this->recipient_copy = trim($V['recipient_copy']);
00160                         }
00161                 }
00162         }
00163 
00172         function addAttachment($file, $filename)        {
00173                 $content = $this->getURL($file);                // We fetch the content and the mime-type
00174                 $fileInfo = $this->split_fileref($filename);
00175                 if ($fileInfo['fileext'] == 'gif')      {$content_type = 'image/gif';}
00176                 if ($fileInfo['fileext'] == 'bmp')      {$content_type = 'image/bmp';}
00177                 if ($fileInfo['fileext'] == 'jpg' || $fileInfo['fileext'] == 'jpeg')    {$content_type = 'image/jpeg';}
00178                 if ($fileInfo['fileext'] == 'html' || $fileInfo['fileext'] == 'htm')    {$content_type = 'text/html';}
00179                 if (!$content_type) {$content_type = 'application/octet-stream';}
00180 
00181                 if ($content)   {
00182                         $theArr['content_type']= $content_type;
00183                         $theArr['content']= $content;
00184                         $theArr['filename']= $filename;
00185                         $this->theParts['attach'][]=$theArr;
00186                         return true;
00187                 } else { return false;}
00188         }
00189 }
00190 
00191 
00192 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_formmail.php'])  {
00193         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_formmail.php']);
00194 }
00195 ?>


Généré par Les spécialistes TYPO3 avec  doxygen 1.4.6