/** * 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 Contains values for the field names listed above (with slashes removed if from POST input) * @param boolean Whether to base64 encode the mail content * @return void */ function start($valueList, $base64 = false) { $this->mailMessage = t3lib_div::makeInstance('t3lib_mail_Message'); 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; } 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 ' . t3lib_div::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 (!t3lib_div::validEmail($this->fromAddress)) { $this->fromAddress = t3lib_utility_Mail::getSystemFromAddress(); $this->fromName = t3lib_utility_Mail::getSystemFromName(); } $this->replyToAddress = $valueList['replyto_email'] ? $valueList['replyto_email'] : $this->fromAddress; $this->priority = $valueList['priority'] ? t3lib_div::intInRange($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 = t3lib_div::hmac($this->autoRespondMessage); if ($autoRespondChecksum !== $correctHmacChecksum) { t3lib_div::sysLog('Possible misuse of t3lib_formmail auto respond method. Subject: ' . $valueList['subject'], 'Core', 3); return; } else { $this->autoRespondMessage = $this->sanitizeHeaderString($this->autoRespondMessage); } } $plainTextContent = ''; $htmlContent = '<table border="0" cellpadding="2" cellspacing="2">'; // Runs through $V and generates the mail if (is_array($valueList)) { foreach ($valueList as $key => $val) { if (!t3lib_div::inList($this->reserved_names, $key)) { $space = strlen($val) > 60 ? LF : ''; $val = is_array($val) ? implode($val, LF) : $val; // convert form data from renderCharset to mail charset (HTML may use entities) $plainTextValue = $val; $HtmlValue = htmlspecialchars($val); $plainTextContent .= strtoupper($key) . ': ' . $space . $plainTextValue . LF . $space; $htmlContent .= '<tr><td bgcolor="#eeeeee"><font face="Verdana" size="1"><strong>' . strtoupper($key) . '</strong></font></td><td bgcolor="#eeeeee"><font face="Verdana" size="1">' . nl2br($HtmlValue) . ' </font></td></tr>'; } } } $htmlContent .= '</table>'; $this->plainContent = $plainTextContent; if ($valueList['html_enabled']) { $this->mailMessage->setBody($htmlContent, 'text/html'); $this->mailMessage->addPart($plainTextContent, 'text/plain'); } else { $this->mailMessage->setBody($plainTextContent, 'text/plain'); } for ($a = 0; $a < 10; $a++) { $variableName = 'attachment' . ($a ? $a : ''); if (!isset($_FILES[$variableName])) { continue; } if (!is_uploaded_file($_FILES[$variableName]['tmp_name'])) { t3lib_div::sysLog('Possible abuse of t3lib_formmail: temporary file "' . $_FILES[$variableName]['tmp_name'] . '" ("' . $_FILES[$variableName]['name'] . '") was not an uploaded file.', 'Core', 3); } if ($_FILES[$variableName]['tmp_name']['error'] !== UPLOAD_ERR_OK) { t3lib_div::sysLog('Error in uploaded file in t3lib_formmail: temporary file "' . $_FILES[$variableName]['tmp_name'] . '" ("' . $_FILES[$variableName]['name'] . '") Error code: ' . $_FILES[$variableName]['tmp_name']['error'], 'Core', 3); } $theFile = t3lib_div::upload_to_tempfile($_FILES[$variableName]['tmp_name']); $theName = $_FILES[$variableName]['name']; if ($theFile && file_exists($theFile)) { if (filesize($theFile) < $GLOBALS['TYPO3_CONF_VARS']['FE']['formmailMaxAttachmentSize']) { $this->mailMessage->attach(Swift_Attachment::fromPath($theFile)->setFilename($theName)); } } $this->temporaryFiles[] = $theFile; } $from = $this->fromName ? array($this->fromAddress => $this->fromName) : array($this->fromAddress); $this->recipient = $this->parseAddresses($valueList['recipient']); $this->mailMessage->setSubject($this->subject)->setFrom($from)->setTo($this->recipient)->setPriority($this->priority); $replyTo = $this->replyToName ? array($this->replyToAddress => $this->replyToName) : array($this->replyToAddress); $this->mailMessage->addReplyTo($replyTo); $this->mailMessage->getHeaders()->addTextHeader('Organization', $this->organisation); if ($valueList['recipient_copy']) { $this->mailMessage->addCc($this->parseAddresses($valueList['recipient_copy'])); } if ($this->characterSet) { $this->mailMessage->setCharset($this->characterSet); } // Ignore target encoding. This is handled automatically by Swift Mailer and overriding the defaults // is not worth the trouble // log dirty header lines if ($this->dirtyHeaders) { t3lib_div::sysLog('Possible misuse of t3lib_formmail: see TYPO3 devLog', 'Core', 3); if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['enable_DLOG']) { t3lib_div::devLog('t3lib_formmail: ' . t3lib_div::arrayToLogString($this->dirtyHeaders, '', 200), 'Core', 3); } } } }
/** * Build and send warning email when new broken links were found. * * @param string $pageSections: Content of page section * @param string $modTS: TSconfig array * @return bool TRUE if mail was sent, FALSE if or not */ protected function reportEmail($pageSections, $modTS) { $content = t3lib_parsehtml::substituteSubpart($this->templateMail, '###PAGE_SECTION###', $pageSections); /** @var array $markerArray */ $markerArray = array(); /** @var array $validEmailList */ $validEmailList = array(); /** @var boolean $sendEmail */ $sendEmail = TRUE; $markerArray['totalBrokenLink'] = $this->totalBrokenLink; $markerArray['totalBrokenLink_old'] = $this->oldTotalBrokenLink; $content = t3lib_parsehtml::substituteMarkerArray($content, $markerArray, '###|###', TRUE, TRUE); /** @var t3lib_mail_Message $mail */ $mail = t3lib_div::makeInstance('t3lib_mail_Message'); if (empty($modTS['mail.']['fromemail'])) { $modTS['mail.']['fromemail'] = t3lib_utility_Mail::getSystemFromAddress(); } if (empty($modTS['mail.']['fromname'])) { $modTS['mail.']['fromname'] = t3lib_utility_Mail::getSystemFromName(); } if (t3lib_div::validEmail($modTS['mail.']['fromemail'])) { $mail->setFrom(array($modTS['mail.']['fromemail'] => $modTS['mail.']['fromname'])); } else { throw new Exception($GLOBALS['LANG']->sL('LLL:EXT:linkvalidator/locallang.xml:tasks.error.invalidFromEmail'), '1295476760'); } if (t3lib_div::validEmail($modTS['mail.']['replytoemail'])) { $mail->setReplyTo(array($modTS['mail.']['replytoemail'] => $modTS['mail.']['replytoname'])); } if (!empty($modTS['mail.']['subject'])) { $mail->setSubject($modTS['mail.']['subject']); } else { throw new Exception($GLOBALS['LANG']->sL('LLL:EXT:linkvalidator/locallang.xml:tasks.error.noSubject'), '1295476808'); } if (!empty($this->email)) { $emailList = t3lib_div::trimExplode(',', $this->email); foreach ($emailList as $emailAdd) { if (!t3lib_div::validEmail($emailAdd)) { throw new Exception($GLOBALS['LANG']->sL('LLL:EXT:linkvalidator/locallang.xml:tasks.error.invalidToEmail'), '1295476821'); } else { $validEmailList[] = $emailAdd; } } } if (is_array($validEmailList) && !empty($validEmailList)) { $mail->setTo($this->email); } else { $sendEmail = FALSE; } if ($sendEmail) { $mail->setBody($content, 'text/html'); $mail->send(); } return $sendEmail; }