コード例 #1
0
ファイル: Dmail.php プロジェクト: kartolo/direct_mail
 /**
  * Send mail to recipient based on table.
  *
  * @param array $idLists List of recipient ID
  * @param string $table Table name
  * @param Dmailer $htmlmail Object of the dmailer script
  *
  * @return int Total of sent mail
  * @todo: remove htmlmail. sending mails to table
  */
 protected function sendTestMailToTable(array $idLists, $table, Dmailer $htmlmail)
 {
     $sentFlag = 0;
     if (is_array($idLists[$table])) {
         if ($table != 'PLAINLIST') {
             $recs = DirectMailUtility::fetchRecordsListValues($idLists[$table], $table, '*');
         } else {
             $recs = $idLists['PLAINLIST'];
         }
         foreach ($recs as $rec) {
             $recipRow = $htmlmail->convertFields($rec);
             $recipRow['sys_dmail_categories_list'] = $htmlmail->getListOfRecipentCategories($table, $recipRow['uid']);
             $kc = substr($table, 0, 1);
             $returnCode = $htmlmail->dmailer_sendAdvanced($recipRow, $kc == 'p' ? 'P' : $kc);
             if ($returnCode) {
                 $sentFlag++;
             }
         }
     }
     return $sentFlag;
 }
コード例 #2
0
ファイル: Dmail.php プロジェクト: preinboth/direct_mail
 /**
  * sending the mail.
  * if it's a test mail, then will be sent directly.
  * if it's a mass-send mail, only update the DB record. the dmailer script will send it.
  *
  * @param	array		$row: directmal DB record
  * @return	string		Messages if the mail is sent or planned to sent
  * @todo	remove htmlmail. sending test mail
  */
 function cmd_send_mail($row)
 {
     // Preparing mailer
     /** @var $htmlmail Dmailer */
     $htmlmail = GeneralUtility::makeInstance('DirectMailTeam\\DirectMail\\Dmailer');
     $htmlmail->nonCron = 1;
     $htmlmail->start();
     $htmlmail->dmailer_prepare($row);
     // send out non-personalized emails
     $simpleMailMode = GeneralUtility::_GP('mailingMode_simple');
     $sentFlag = FALSE;
     if ($simpleMailMode) {
         // step 4, sending simple test emails
         // setting Testmail flag
         $htmlmail->testmail = $this->params['testmail'];
         // Fixing addresses:
         $addresses = GeneralUtility::_GP('SET');
         $addressList = $addresses['dmail_test_email'] ? $addresses['dmail_test_email'] : $this->MOD_SETTINGS['dmail_test_email'];
         $addresses = preg_split('|[' . LF . ',;]|', $addressList);
         foreach ($addresses as $key => $val) {
             $addresses[$key] = trim($val);
             if (!GeneralUtility::validEmail($addresses[$key])) {
                 unset($addresses[$key]);
             }
         }
         $hash = array_flip($addresses);
         $addresses = array_keys($hash);
         $addressList = implode(',', $addresses);
         if ($addressList) {
             // Sending the same mail to lots of recipients
             $htmlmail->dmailer_sendSimple($addressList);
             $sentFlag = TRUE;
             /** @var $flashMessage FlashMessage */
             $flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $GLOBALS['LANG']->getLL('send_was_sent') . '<br /><br />' . $GLOBALS['LANG']->getLL('send_recipients') . '<br />' . htmlspecialchars($addressList), $GLOBALS['LANG']->getLL('send_sending'), FlashMessage::OK);
             $this->noView = 1;
         }
     } elseif ($this->CMD == 'send_mail_test') {
         // step 4, sending test personalized test emails
         // setting Testmail flag
         $htmlmail->testmail = $this->params['testmail'];
         if (GeneralUtility::_GP('tt_address_uid')) {
             //personalized to tt_address
             $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('tt_address.*', 'tt_address LEFT JOIN pages ON pages.uid=tt_address.pid', 'tt_address.uid=' . intval(GeneralUtility::_GP('tt_address_uid')) . ' AND ' . $this->perms_clause . BackendUtility::deleteClause('pages') . BackendUtility::BEenableFields('tt_address') . BackendUtility::deleteClause('tt_address'));
             if ($recipRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
                 $recipRow = \DirectMailTeam\DirectMail\Dmailer::convertFields($recipRow);
                 $recipRow['sys_dmail_categories_list'] = $htmlmail->getListOfRecipentCategories('tt_address', $recipRow['uid']);
                 $htmlmail->dmailer_sendAdvanced($recipRow, 't');
                 $sentFlag = true;
                 /** @var $flashMessage FlashMessage */
                 $flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', sprintf($GLOBALS['LANG']->getLL('send_was_sent_to_name'), htmlspecialchars($recipRow['name']) . htmlspecialchars(' <' . $recipRow['email'] . '>')), $GLOBALS['LANG']->getLL('send_sending'), FlashMessage::OK);
             }
             $GLOBALS['TYPO3_DB']->sql_free_result($res);
         } elseif (is_array(GeneralUtility::_GP('sys_dmail_group_uid'))) {
             // personalized to group
             $result = $this->cmd_compileMailGroup(GeneralUtility::_GP('sys_dmail_group_uid'));
             $idLists = $result['queryInfo']['id_lists'];
             $sendFlag = 0;
             $sendFlag += $this->sendTestMailToTable($idLists, 'tt_address', $htmlmail);
             $sendFlag += $this->sendTestMailToTable($idLists, 'fe_users', $htmlmail);
             $sendFlag += $this->sendTestMailToTable($idLists, 'PLAINLIST', $htmlmail);
             $sendFlag += $this->sendTestMailToTable($idLists, $this->userTable, $htmlmail);
             /** @var $flashMessage FlashMessage */
             $flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', sprintf($GLOBALS['LANG']->getLL('send_was_sent_to_number'), $sendFlag), $GLOBALS['LANG']->getLL('send_sending'), FlashMessage::OK);
         }
     } else {
         // step 5, sending personalized emails to the mailqueue
         // prepare the email for sending with the mailqueue
         $recipientGroups = GeneralUtility::_GP('mailgroup_uid');
         if (GeneralUtility::_GP('mailingMode_mailGroup') && $this->sys_dmail_uid && is_array($recipientGroups)) {
             // Update the record:
             $result = $this->cmd_compileMailGroup($recipientGroups);
             $queryInfo = $result['queryInfo'];
             $distributionTime = intval(strtotime(GeneralUtility::_GP('send_mail_datetime')));
             if ($distributionTime < time()) {
                 $distributionTime = time();
             }
             $updateFields = array('recipientGroups' => implode(',', $recipientGroups), 'scheduled' => $distributionTime, 'query_info' => serialize($queryInfo));
             if (GeneralUtility::_GP('testmail')) {
                 $updateFields['subject'] = $this->params['testmail'] . ' ' . $row['subject'];
             }
             // create a draft version of the record
             if (GeneralUtility::_GP('savedraft')) {
                 if ($row['type'] == 0) {
                     $updateFields['type'] = 2;
                 } else {
                     $updateFields['type'] = 3;
                 }
                 $updateFields['scheduled'] = 0;
                 $content = $GLOBALS['LANG']->getLL('send_draft_scheduler');
                 $sectionTitle = $GLOBALS['LANG']->getLL('send_draft_saved');
             } else {
                 $content = $GLOBALS['LANG']->getLL('send_was_scheduled_for') . ' ' . BackendUtility::datetime($distributionTime);
                 $sectionTitle = $GLOBALS['LANG']->getLL('send_was_scheduled');
             }
             $sentFlag = TRUE;
             $GLOBALS['TYPO3_DB']->exec_UPDATEquery('sys_dmail', 'uid=' . intval($this->sys_dmail_uid), $updateFields);
             /** @var $flashMessage FlashMessage */
             $flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $sectionTitle . '<br /><br />' . $content, $GLOBALS['LANG']->getLL('dmail_wiz5_sendmass'), FlashMessage::OK);
         }
     }
     // Setting flags and update the record:
     if ($sentFlag && $this->CMD == 'send_mail_final') {
         $GLOBALS['TYPO3_DB']->exec_UPDATEquery('sys_dmail', 'uid=' . intval($this->sys_dmail_uid), array('issent' => 1));
     }
     return $flashMessage->render();
 }