コード例 #1
0
ファイル: EmailService.php プロジェクト: HOCHZWEI/h2dmailsub
 /**
  * Sends an e-mail, if sender and recipient is an valid e-mail address
  *
  * @param string $sender The sender
  * @param string $recipient The recipient
  * @param string $subject The subject
  * @param string $body E-Mail body
  * @param string $name Optional sendername
  *
  * @return bool true/false if message is sent
  */
 public function sendEmailMessage($sender, $recipient, $subject, $body, $name)
 {
     if (GeneralUtility::validEmail($sender) && GeneralUtility::validEmail($recipient)) {
         $this->mail->setFrom($sender, $name);
         $this->mail->setSubject($subject);
         $this->mail->setBody($body, 'text/html');
         $this->mail->setTo($recipient);
         $this->mail->send();
         return $this->mail->isSent();
     } else {
         return false;
     }
 }
コード例 #2
0
 /**
  * Sends an e-mail, if sender and recipient is an valid e-mail address
  *
  * @param string $sender The sender
  * @param string $recipient The recipient
  * @param string $subject The subject
  * @param string $body E-Mail body
  * @param string $name Optional sendername
  * @param array $attachments Array of files (e.g. ['/absolute/path/doc.pdf'])
  *
  * @return bool TRUE/FALSE if message is sent
  */
 public function sendEmailMessage($sender, $recipient, $subject, $body, $name = null, $attachments = [])
 {
     if (GeneralUtility::validEmail($sender) && GeneralUtility::validEmail($recipient)) {
         $this->initialize();
         $this->mailer->setFrom($sender, $name);
         $this->mailer->setSubject($subject);
         $this->mailer->setBody($body, 'text/html');
         $this->mailer->setTo($recipient);
         $this->addAttachments($attachments);
         $this->mailer->send();
         return $this->mailer->isSent();
     } else {
         return false;
     }
 }
コード例 #3
0
 /**
  * Add the HTML content
  *
  * Add a MimePart of the type text/html to the message.
  *
  * @return void
  */
 protected function setHtmlContent()
 {
     /** @var $view \TYPO3\CMS\Form\View\Mail\Html\HtmlView */
     $view = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Form\\View\\Mail\\Html\\HtmlView', $this->form, $this->typoScript);
     $htmlContent = $view->get();
     $this->mailMessage->setBody($htmlContent, 'text/html');
 }
コード例 #4
0
 /**
  * send email on new/update.
  *
  * @param string                                    $subjectKey
  * @param \JWeiland\Clubdirectory\Domain\Model\Club $club
  *
  * @return int The amound of email receivers
  */
 public function sendMail($subjectKey, \JWeiland\Clubdirectory\Domain\Model\Club $club)
 {
     $this->view->assign('club', $club);
     $this->mail->setFrom($this->extConf->getEmailFromAddress(), $this->extConf->getEmailFromName());
     $this->mail->setTo($this->extConf->getEmailToAddress(), $this->extConf->getEmailToName());
     $this->mail->setSubject(LocalizationUtility::translate('email.subject.' . $subjectKey, 'clubdirectory'));
     $this->mail->setBody($this->view->render(), 'text/html');
     return $this->mail->send();
 }
コード例 #5
0
ファイル: MailView.php プロジェクト: raphaelweber/faq
 /**
  * assign content
  *
  * @return MailView
  */
 protected function assignContent()
 {
     $html = parent::render();
     $request = $this->controllerContext->getRequest();
     $resetFormat = $request->getFormat();
     $request->setFormat('txt');
     if ($this->canRender($this->controllerContext)) {
         $txt = parent::render();
     }
     $request->setFormat($resetFormat);
     $this->mail->setBody($html, 'text/html');
     if (isset($txt) && strlen($txt)) {
         $this->mail->addPart($txt, 'text/plain');
     }
     return $this;
 }
コード例 #6
0
 /**
  * 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 boolean $base64 Whether to base64 encode the mail content
  * @return void
  * @todo Define visibility
  */
 public function start($valueList, $base64 = FALSE)
 {
     $this->mailMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Mail\\MailMessage');
     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 ' . \TYPO3\CMS\Core\Utility\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 (!\TYPO3\CMS\Core\Utility\GeneralUtility::validEmail($this->fromAddress)) {
             $this->fromAddress = \TYPO3\CMS\Core\Utility\MailUtility::getSystemFromAddress();
             $this->fromName = \TYPO3\CMS\Core\Utility\MailUtility::getSystemFromName();
         }
         $this->replyToAddress = $valueList['replyto_email'] ? $valueList['replyto_email'] : $this->fromAddress;
         $this->priority = $valueList['priority'] ? \TYPO3\CMS\Core\Utility\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 = \TYPO3\CMS\Core\Utility\GeneralUtility::hmac($this->autoRespondMessage);
             if ($autoRespondChecksum !== $correctHmacChecksum) {
                 \TYPO3\CMS\Core\Utility\GeneralUtility::sysLog('Possible misuse of t3lib_formmail auto respond method. Subject: ' . $valueList['subject'], 'Core', \TYPO3\CMS\Core\Utility\GeneralUtility::SYSLOG_SEVERITY_ERROR);
                 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 (!\TYPO3\CMS\Core\Utility\GeneralUtility::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) . '&nbsp;</font></td></tr>';
                 }
             }
         }
         $htmlContent .= '</table>';
         $this->plainContent = $plainTextContent;
         if ($valueList['html_enabled']) {
             $this->mailMessage->setBody($htmlContent, 'text/html', $this->characterSet);
             $this->mailMessage->addPart($plainTextContent, 'text/plain', $this->characterSet);
         } else {
             $this->mailMessage->setBody($plainTextContent, 'text/plain', $this->characterSet);
         }
         for ($a = 0; $a < 10; $a++) {
             $variableName = 'attachment' . ($a ? $a : '');
             if (!isset($_FILES[$variableName])) {
                 continue;
             }
             if (!is_uploaded_file($_FILES[$variableName]['tmp_name'])) {
                 \TYPO3\CMS\Core\Utility\GeneralUtility::sysLog('Possible abuse of t3lib_formmail: temporary file "' . $_FILES[$variableName]['tmp_name'] . '" ("' . $_FILES[$variableName]['name'] . '") was not an uploaded file.', 'Core', \TYPO3\CMS\Core\Utility\GeneralUtility::SYSLOG_SEVERITY_ERROR);
             }
             if ($_FILES[$variableName]['tmp_name']['error'] !== UPLOAD_ERR_OK) {
                 \TYPO3\CMS\Core\Utility\GeneralUtility::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', \TYPO3\CMS\Core\Utility\GeneralUtility::SYSLOG_SEVERITY_ERROR);
             }
             $theFile = \TYPO3\CMS\Core\Utility\GeneralUtility::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->setReplyTo($replyTo);
         $this->mailMessage->getHeaders()->addTextHeader('Organization', $this->organisation);
         if ($valueList['recipient_copy']) {
             $this->mailMessage->setCc($this->parseAddresses($valueList['recipient_copy']));
         }
         $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) {
             \TYPO3\CMS\Core\Utility\GeneralUtility::sysLog('Possible misuse of t3lib_formmail: see TYPO3 devLog', 'Core', \TYPO3\CMS\Core\Utility\GeneralUtility::SYSLOG_SEVERITY_ERROR);
             if ($GLOBALS['TYPO3_CONF_VARS']['SYS']['enable_DLOG']) {
                 \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('t3lib_formmail: ' . \TYPO3\CMS\Core\Utility\GeneralUtility::arrayToLogString($this->dirtyHeaders, '', 200), 'Core', 3);
             }
         }
     }
 }
コード例 #7
0
 /**
  * Add mail body html
  *
  * @param MailMessage $message
  * @param array $email
  * @return MailMessage
  */
 protected function addHtmlBody(MailMessage $message, array $email)
 {
     if ($email['format'] !== 'plain') {
         $message->setBody($this->createEmailBody($email), 'text/html');
     }
     return $message;
 }
コード例 #8
0
 /**
  * Add the HTML content
  *
  * Add a MimePart of the type text/html to the message.
  *
  * @return void
  */
 protected function setHtmlContent()
 {
     $htmlContent = $this->getView($this->htmlMailTemplatePath)->render();
     $this->mailMessage->setBody($htmlContent, 'text/html');
 }
コード例 #9
0
ファイル: EmailPipe.php プロジェクト: kersten/flux
 /**
  * @param string $data
  * @return MailMessage
  */
 protected function prepareEmail($data)
 {
     $body = $this->getBody();
     $sender = $this->getSender();
     $recipient = $this->getRecipient();
     if (TRUE === is_array($recipient)) {
         list($recipientAddress, $recipientName) = $recipient;
     } else {
         $recipientAddress = $recipient;
         $recipientName = NULL;
     }
     if (TRUE === is_array($sender)) {
         list($senderAddress, $senderName) = $sender;
     } else {
         $senderAddress = $sender;
         $senderName = NULL;
     }
     $subject = $this->getSubject();
     if (TRUE === is_string($data)) {
         $body = $data;
     }
     $message = new MailMessage();
     $message->setSubject($subject);
     $message->setFrom($senderAddress, $senderName);
     $message->setTo($recipientAddress, $recipientName);
     $message->setBody($body);
     return $message;
 }
コード例 #10
0
 /**
  * Sets the HTML body
  *
  * @param string $htmlBody The HTML body
  *
  * @return void
  */
 public function setHtmlBody($htmlBody)
 {
     $this->message->setBody($htmlBody, 'text/html', 'utf8');
 }