Documentation TYPO3 par Ameos |
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 var $dirtyHeaders = array(); // collection of suspicious header data, used for logging 00072 00073 00096 function start($V,$base64=false) { 00097 $convCharset = FALSE; // do we need to convert form data? 00098 00099 if ($GLOBALS['TSFE']->config['config']['formMailCharset']) { // Respect formMailCharset if it was set 00100 $this->charset = $GLOBALS['TSFE']->csConvObj->parse_charset($GLOBALS['TSFE']->config['config']['formMailCharset']); 00101 $convCharset = TRUE; 00102 00103 } elseif ($GLOBALS['TSFE']->metaCharset != $GLOBALS['TSFE']->renderCharset) { // Use metaCharset for mail if different from renderCharset 00104 $this->charset = $GLOBALS['TSFE']->metaCharset; 00105 $convCharset = TRUE; 00106 } 00107 00108 parent::start(); 00109 00110 if ($base64 || $V['use_base64']) { $this->useBase64(); } 00111 00112 if (isset($V['recipient'])) { 00113 // convert form data from renderCharset to mail charset 00114 $val = ($V['subject']) ? $V['subject'] : 'Formmail on '.t3lib_div::getIndpEnv('HTTP_HOST'); 00115 $this->subject = ($convCharset && strlen($val)) ? $GLOBALS['TSFE']->csConvObj->conv($val,$GLOBALS['TSFE']->renderCharset,$this->charset) : $val; 00116 $this->subject = $this->sanitizeHeaderString($this->subject); 00117 $val = ($V['from_name']) ? $V['from_name'] : (($V['name'])?$V['name']:''); 00118 $this->from_name = ($convCharset && strlen($val)) ? $GLOBALS['TSFE']->csConvObj->conv($val,$GLOBALS['TSFE']->renderCharset,$this->charset) : $val; 00119 $this->from_name = $this->sanitizeHeaderString($this->from_name); 00120 $this->from_name = preg_match( '/\s|,/', $this->from_name ) >= 1 ? '"'.$this->from_name.'"' : $this->from_name; 00121 $val = ($V['replyto_name']) ? $V['replyto_name'] : $this->from_name; 00122 $this->replyto_name = ($convCharset && strlen($val)) ? $GLOBALS['TSFE']->csConvObj->conv($val,$GLOBALS['TSFE']->renderCharset,$this->charset) : $val; 00123 $this->replyto_name = $this->sanitizeHeaderString($this->replyto_name); 00124 $this->replyto_name = preg_match( '/\s|,/', $this->replyto_name ) > 1 ? '"'.$this->replyto_name.'"' : $this->replyto_name; 00125 $val = ($V['organisation']) ? $V['organisation'] : ''; 00126 $this->organisation = ($convCharset && strlen($val)) ? $GLOBALS['TSFE']->csConvObj->conv($val,$GLOBALS['TSFE']->renderCharset,$this->charset) : $val; 00127 $this->organisation = $this->sanitizeHeaderString($this->organisation); 00128 00129 $this->from_email = ($V['from_email']) ? $V['from_email'] : (($V['email'])?$V['email']:''); 00130 $this->from_email = t3lib_div::validEmail($this->from_email) ? $this->from_email : ''; 00131 $this->replyto_email = ($V['replyto_email']) ? $V['replyto_email'] : $this->from_email; 00132 $this->replyto_email = t3lib_div::validEmail($this->replyto_email) ? $this->replyto_email : ''; 00133 $this->priority = ($V['priority']) ? t3lib_div::intInRange($V['priority'],1,5) : 3; 00134 00135 // Auto responder. 00136 $this->auto_respond_msg = (trim($V['auto_respond_msg']) && $this->from_email) ? trim($V['auto_respond_msg']) : ''; 00137 $this->auto_respond_msg = $this->sanitizeHeaderString($this->auto_respond_msg); 00138 00139 $Plain_content = ''; 00140 $HTML_content = '<table border="0" cellpadding="2" cellspacing="2">'; 00141 00142 // Runs through $V and generates the mail 00143 if (is_array($V)) { 00144 reset($V); 00145 while (list($key,$val)=each($V)) { 00146 if (!t3lib_div::inList($this->reserved_names,$key)) { 00147 $space = (strlen($val)>60)?chr(10):''; 00148 $val = (is_array($val) ? implode($val,chr(10)) : $val); 00149 00150 // convert form data from renderCharset to mail charset (HTML may use entities) 00151 $Plain_val = ($convCharset && strlen($val)) ? $GLOBALS['TSFE']->csConvObj->conv($val,$GLOBALS['TSFE']->renderCharset,$this->charset,0) : $val; 00152 $HTML_val = ($convCharset && strlen($val)) ? $GLOBALS['TSFE']->csConvObj->conv(htmlspecialchars($val),$GLOBALS['TSFE']->renderCharset,$this->charset,1) : htmlspecialchars($val); 00153 00154 $Plain_content.= strtoupper($key).': '.$space.$Plain_val."\n".$space; 00155 $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($HTML_val).' </font></td></tr>'; 00156 } 00157 } 00158 } 00159 $HTML_content.= '</table>'; 00160 00161 if ($V['html_enabled']) { 00162 $this->setHTML($this->encodeMsg($HTML_content)); 00163 } 00164 $this->addPlain($Plain_content); 00165 00166 for ($a=0;$a<10;$a++) { 00167 $varname = 'attachment'.(($a)?$a:''); 00168 $theFile = t3lib_div::upload_to_tempfile($_FILES[$varname]['tmp_name']); 00169 $theName = $_FILES[$varname]['name']; 00170 00171 if ($theFile && @file_exists($theFile)) { 00172 if (filesize($theFile) < 250000) { 00173 $this->addAttachment($theFile, $theName); 00174 } 00175 } 00176 t3lib_div::unlink_tempfile($theFile); 00177 } 00178 00179 $this->setHeaders(); 00180 $this->setContent(); 00181 $this->setRecipient($V['recipient']); 00182 if ($V['recipient_copy']) { 00183 $this->recipient_copy = trim($V['recipient_copy']); 00184 } 00185 // log dirty header lines 00186 if ($this->dirtyHeaders) { 00187 t3lib_div::sysLog( 'Possible misuse of t3lib_formmail: see TYPO3 devLog', 'Core', 3 ); 00188 if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['enable_DLOG']) { 00189 t3lib_div::devLog( 't3lib_formmail: '. t3lib_div::arrayToLogString($this->dirtyHeaders, '', 200 ), 'Core', 3 ); 00190 } 00191 } 00192 } 00193 } 00194 00203 function addAttachment($file, $filename) { 00204 $content = $this->getURL($file); // We fetch the content and the mime-type 00205 $fileInfo = $this->split_fileref($filename); 00206 if ($fileInfo['fileext'] == 'gif') {$content_type = 'image/gif';} 00207 if ($fileInfo['fileext'] == 'bmp') {$content_type = 'image/bmp';} 00208 if ($fileInfo['fileext'] == 'jpg' || $fileInfo['fileext'] == 'jpeg') {$content_type = 'image/jpeg';} 00209 if ($fileInfo['fileext'] == 'html' || $fileInfo['fileext'] == 'htm') {$content_type = 'text/html';} 00210 if (!$content_type) {$content_type = 'application/octet-stream';} 00211 00212 if ($content) { 00213 $theArr['content_type']= $content_type; 00214 $theArr['content']= $content; 00215 $theArr['filename']= $filename; 00216 $this->theParts['attach'][]=$theArr; 00217 return true; 00218 } else { return false;} 00219 } 00220 00221 00228 function sanitizeHeaderString ($string) { 00229 $pattern = '/[\r\n\f\e]/'; 00230 if (preg_match($pattern, $string) > 0) { 00231 $this->dirtyHeaders[] = $string; 00232 $string = ''; 00233 } 00234 return $string; 00235 } 00236 } 00237 00238 00239 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_formmail.php']) { 00240 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_formmail.php']); 00241 } 00242 ?>