frontendController = $frontendController; // Checks if any email-submissions $formtype_mail = isset($_POST['formtype_mail']) || isset($_POST['formtype_mail_x']); if ($formtype_mail) { $refInfo = parse_url(GeneralUtility::getIndpEnv('HTTP_REFERER')); if (GeneralUtility::getIndpEnv('TYPO3_HOST_ONLY') == $refInfo['host'] || $this->frontendController->TYPO3_CONF_VARS['SYS']['doNotCheckReferer']) { if ($this->locDataCheck($_POST['locationData'])) { if ($formtype_mail) { $this->prepareAndSend(); $GLOBALS['TT']->setTSlogMessage('"Check Data Submission": Return value: email', 0); } } } else { $GLOBALS['TT']->setTSlogMessage('"Check Data Submission": HTTP_HOST and REFERER HOST did not match when processing submitted formdata!', 3); } } } /** * Checks if a formmail submission can be sent as email * * @param string $locationData The input from $_POST['locationData'] * @return void|int */ protected function locDataCheck($locationData) { $locData = explode(':', $locationData); if (!$locData[1] || $this->frontendController->sys_page->checkRecord($locData[1], $locData[2], 1)) { // $locData[1] -check means that a record is checked only if the locationData has a value for a record else than the page. if (!empty($this->frontendController->sys_page->getPage($locData[0]))) { return 1; } $GLOBALS['TT']->setTSlogMessage('LocationData Error: The page pointed to by location data (' . $locationData . ') was not accessible.', 2); } else { $GLOBALS['TT']->setTSlogMessage('LocationData Error: Location data (' . $locationData . ') record pointed to was not accessible.', 2); } } /** * Sends the emails from the formmail content object. * * @return void */ protected function prepareAndSend() { $EMAIL_VARS = GeneralUtility::_POST(); $locationData = $EMAIL_VARS['locationData']; unset($EMAIL_VARS['locationData']); unset($EMAIL_VARS['formtype_mail'], $EMAIL_VARS['formtype_mail_x'], $EMAIL_VARS['formtype_mail_y']); $integrityCheck = $this->frontendController->TYPO3_CONF_VARS['FE']['strictFormmail']; if (!$this->frontendController->TYPO3_CONF_VARS['FE']['secureFormmail']) { // Check recipient field: // These two fields are the ones which contain recipient addresses that can be misused to send mail from foreign servers. $encodedFields = explode(',', 'recipient, recipient_copy'); foreach ($encodedFields as $fieldKey) { if ((string)$EMAIL_VARS[$fieldKey] !== '') { // Decode... if ($res = \TYPO3\CMS\Compatibility6\Utility\FormUtility::codeString($EMAIL_VARS[$fieldKey], true)) { $EMAIL_VARS[$fieldKey] = $res; } elseif ($integrityCheck) { // Otherwise abort: $GLOBALS['TT']->setTSlogMessage('"Formmail" discovered a field (' . $fieldKey . ') which could not be decoded to a valid string. Sending formmail aborted due to security reasons!', 3); return; } else { $GLOBALS['TT']->setTSlogMessage('"Formmail" discovered a field (' . $fieldKey . ') which could not be decoded to a valid string. The security level accepts this, but you should consider a correct coding though!', 2); } } } } else { $locData = explode(':', $locationData); $record = $this->frontendController->sys_page->checkRecord($locData[1], $locData[2], 1); $EMAIL_VARS['recipient'] = $record['subheader']; $EMAIL_VARS['recipient_copy'] = $this->extractRecipientCopy($record['bodytext']); } // Hook for preprocessing of the content for formmails: if (is_array($this->frontendController->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['sendFormmail-PreProcClass'])) { foreach ($this->frontendController->TYPO3_CONF_VARS['SC_OPTIONS']['tslib/class.tslib_fe.php']['sendFormmail-PreProcClass'] as $_classRef) { $_procObj = GeneralUtility::getUserObj($_classRef); $EMAIL_VARS = $_procObj->sendFormmail_preProcessVariables($EMAIL_VARS, $this); } } $this->start($EMAIL_VARS); $r = $this->sendtheMail(); $GLOBALS['TT']->setTSlogMessage('"Formmail" invoked, sending mail to ' . $EMAIL_VARS['recipient'], 0); } /** * Extracts the value of recipient copy field from a formmail CE bodytext * * @param string $bodytext The content of the related bodytext field * @return string The value of the recipient_copy field, or an empty string */ protected function extractRecipientCopy($bodytext) { $fdef = array(); //|recipient_copy=hidden|karsten@localhost.localdomain preg_match('/^[\\s]*\\|[\\s]*recipient_copy[\\s]*=[\\s]*hidden[\\s]*\\|(.*)$/m', $bodytext, $fdef); return $fdef[1] ?: ''; } /** * Start function * This class is able to generate a mail in formmail-style from the data in $V * Fields: * * [recipient]: email-adress of the one to receive the mail. If array, then all values are expected to be recipients * [attachment]: .... * * [subject]: The subject of the mail * [from_email]: Sender email. If not set, [email] is used * [from_name]: Sender name. If not set, [name] is used * [replyto_email]: Reply-to email. If not set [from_email] is used * [replyto_name]: Reply-to name. If not set [from_name] is used * [organisation]: Organization (header) * [priority]: Priority, 1-5, default 3 * [html_enabled]: If mail is sent as html * [use_base64]: If set, base64 encoding will be used instead of quoted-printable * * @param array $valueList Contains values for the field names listed above (with slashes removed if from POST input) * @param bool $base64 Whether to base64 encode the mail content * @return void */ public function start($valueList, $base64 = false) { $this->mailMessage = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Mail\MailMessage::class); if ($GLOBALS['TSFE']->config['config']['formMailCharset']) { // Respect formMailCharset if it was set $this->characterSet = $GLOBALS['TSFE']->csConvObj->parse_charset($GLOBALS['TSFE']->config['config']['formMailCharset']); } elseif ($GLOBALS['TSFE']->metaCharset != $GLOBALS['TSFE']->renderCharset) { // Use metaCharset for mail if different from renderCharset $this->characterSet = $GLOBALS['TSFE']->metaCharset; } else { // Otherwise use renderCharset as default $this->characterSet = $GLOBALS['TSFE']->renderCharset; } if ($base64 || $valueList['use_base64']) { $this->encoding = 'base64'; } if (isset($valueList['recipient'])) { // Convert form data from renderCharset to mail charset $this->subject = $valueList['subject'] ? $valueList['subject'] : 'Formmail on ' . GeneralUtility::getIndpEnv('HTTP_HOST'); $this->subject = $this->sanitizeHeaderString($this->subject); $this->fromName = $valueList['from_name'] ? $valueList['from_name'] : ($valueList['name'] ? $valueList['name'] : ''); $this->fromName = $this->sanitizeHeaderString($this->fromName); $this->replyToName = $valueList['replyto_name'] ? $valueList['replyto_name'] : $this->fromName; $this->replyToName = $this->sanitizeHeaderString($this->replyToName); $this->organisation = $valueList['organisation'] ? $valueList['organisation'] : ''; $this->organisation = $this->sanitizeHeaderString($this->organisation); $this->fromAddress = $valueList['from_email'] ? $valueList['from_email'] : ($valueList['email'] ? $valueList['email'] : ''); if (!GeneralUtility::validEmail($this->fromAddress)) { $this->fromAddress = MailUtility::getSystemFromAddress(); $this->fromName = MailUtility::getSystemFromName(); } $this->replyToAddress = $valueList['replyto_email'] ? $valueList['replyto_email'] : $this->fromAddress; $this->priority = $valueList['priority'] ? MathUtility::forceIntegerInRange($valueList['priority'], 1, 5) : 3; // Auto responder $this->autoRespondMessage = trim($valueList['auto_respond_msg']) && $this->fromAddress ? trim($valueList['auto_respond_msg']) : ''; if ($this->autoRespondMessage !== '') { // Check if the value of the auto responder message has been modified with evil intentions $autoRespondChecksum = $valueList['auto_respond_checksum']; $correctHmacChecksum = GeneralUtility::hmac($this->autoRespondMessage, 'content_form'); if ($autoRespondChecksum !== $correctHmacChecksum) { GeneralUtility::sysLog('Possible misuse of DataSubmissionController auto respond method. Subject: ' . $valueList['subject'], 'core', GeneralUtility::SYSLOG_SEVERITY_ERROR); return; } else { $this->autoRespondMessage = $this->sanitizeHeaderString($this->autoRespondMessage); } } $plainTextContent = ''; $htmlContent = '
| ' . strtoupper($key) . ' | ' . nl2br($HtmlValue) . ' |