00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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 $convCharset = FALSE;
00097
00098 if ($GLOBALS['TSFE']->metaCharset != $GLOBALS['TSFE']->renderCharset) {
00099 $this->charset = $GLOBALS['TSFE']->metaCharset;
00100 $convCharset = TRUE;
00101 }
00102
00103 if ($GLOBALS['TSFE']->config['config']['formMailCharset']) {
00104 $this->charset = $GLOBALS['TSFE']->csConvObj->parse_charset($GLOBALS['TSFE']->config['config']['formMailCharset']);
00105 $convCharset = TRUE;
00106 }
00107
00108 parent::start();
00109
00110 if ($base64 || $V['use_base64']) { $this->useBase64(); }
00111
00112 if (isset($V['recipient'])) {
00113
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 $val = ($V['from_name']) ? $V['from_name'] : (($V['name'])?$V['name']:'');
00117 $this->from_name = ($convCharset && strlen($val)) ? $GLOBALS['TSFE']->csConvObj->conv($val,$GLOBALS['TSFE']->renderCharset,$this->charset) : $val;
00118 $val = ($V['replyto_name']) ? $V['replyto_name'] : $this->from_name;
00119 $this->replyto_name = ($convCharset && strlen($val)) ? $GLOBALS['TSFE']->csConvObj->conv($val,$GLOBALS['TSFE']->renderCharset,$this->charset) : $val;
00120 $val = ($V['organisation']) ? $V['organisation'] : '';
00121 $this->organisation = ($convCharset && strlen($val)) ? $GLOBALS['TSFE']->csConvObj->conv($val,$GLOBALS['TSFE']->renderCharset,$this->charset) : $val;
00122
00123 $this->from_email = ($V['from_email']) ? $V['from_email'] : (($V['email'])?$V['email']:'');
00124 $this->replyto_email = ($V['replyto_email']) ? $V['replyto_email'] : $this->from_email;
00125 $this->priority = ($V['priority']) ? t3lib_div::intInRange($V['priority'],1,5) : 3;
00126
00127
00128 $this->auto_respond_msg = (trim($V['auto_respond_msg']) && $this->from_email) ? trim($V['auto_respond_msg']) : '';
00129
00130 $Plain_content = '';
00131 $HTML_content = '<table border="0" cellpadding="2" cellspacing="2">';
00132
00133
00134 if (is_array($V)) {
00135 reset($V);
00136 while (list($key,$val)=each($V)) {
00137 if (!t3lib_div::inList($this->reserved_names,$key)) {
00138 $space = (strlen($val)>60)?chr(10):'';
00139 $val = (is_array($val) ? implode($val,chr(10)) : $val);
00140
00141
00142 $Plain_val = ($convCharset && strlen($val)) ? $GLOBALS['TSFE']->csConvObj->conv($val,$GLOBALS['TSFE']->renderCharset,$this->charset,0) : $val;
00143 $HTML_val = ($convCharset && strlen($val)) ? $GLOBALS['TSFE']->csConvObj->conv(htmlspecialchars($val),$GLOBALS['TSFE']->renderCharset,$this->charset,1) : htmlspecialchars($val);
00144
00145 $Plain_content.= strtoupper($key).': '.$space.$Plain_val."\n".$space;
00146 $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>';
00147 }
00148 }
00149 }
00150 $HTML_content.= '</table>';
00151
00152 if ($V['html_enabled']) {
00153 $this->setHTML($this->encodeMsg($HTML_content));
00154 }
00155 $this->addPlain($Plain_content);
00156
00157 for ($a=0;$a<10;$a++) {
00158 $varname = 'attachment'.(($a)?$a:'');
00159 $theFile = t3lib_div::upload_to_tempfile($_FILES[$varname]['tmp_name']);
00160 $theName = $_FILES[$varname]['name'];
00161
00162 if ($theFile && @file_exists($theFile)) {
00163 if (filesize($theFile) < 250000) {
00164 $this->addAttachment($theFile, $theName);
00165 }
00166 }
00167 t3lib_div::unlink_tempfile($theFile);
00168 }
00169
00170 $this->setHeaders();
00171 $this->setContent();
00172 $this->setRecipient($V['recipient']);
00173 if ($V['recipient_copy']) {
00174 $this->recipient_copy = trim($V['recipient_copy']);
00175 }
00176 }
00177 }
00178
00187 function addAttachment($file, $filename) {
00188 $content = $this->getURL($file);
00189 $fileInfo = $this->split_fileref($filename);
00190 if ($fileInfo['fileext'] == 'gif') {$content_type = 'image/gif';}
00191 if ($fileInfo['fileext'] == 'bmp') {$content_type = 'image/bmp';}
00192 if ($fileInfo['fileext'] == 'jpg' || $fileInfo['fileext'] == 'jpeg') {$content_type = 'image/jpeg';}
00193 if ($fileInfo['fileext'] == 'html' || $fileInfo['fileext'] == 'htm') {$content_type = 'text/html';}
00194 if (!$content_type) {$content_type = 'application/octet-stream';}
00195
00196 if ($content) {
00197 $theArr['content_type']= $content_type;
00198 $theArr['content']= $content;
00199 $theArr['filename']= $filename;
00200 $this->theParts['attach'][]=$theArr;
00201 return true;
00202 } else { return false;}
00203 }
00204 }
00205
00206
00207 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_formmail.php']) {
00208 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_formmail.php']);
00209 }
00210 ?>