Commit d638910b authored by Carsten  Rose's avatar Carsten Rose
Browse files

#4255 / Attachments fuer 'Email'

 Manual.rst: description of new options for MAIL_LOG and Report/sendmail.
 sendEmail: added new perl script.
 Report.php: $mailarr renamed to $mailConfig. convertToken() updated.
 Sendmail.php: commented mb_send_mail(). New sendEmail().
 Config.php: new options MAIL_LOG.
 Store.php: Update SUSTEM_SEND_E_MAIL
parent 7b497c32
......@@ -68,7 +68,7 @@ Preparation for Ubuntu 14.04::
Preparation for Ubuntu 16.04::
sudo apt install php7.0-intl
sudo apt install pdftk libxrender1 file # for file upload, PDF and 'HTML to PDF' (wkhtmltopdf)
sudo apt install pdftk libxrender1 file pdf2svg # for file upload, PDF and 'HTML to PDF' (wkhtmltopdf), PDF split
.. _wkhtml:
......@@ -238,11 +238,15 @@ config.qfq.ini
+-----------------------------+-------------------------------------------------+----------------------------------------------------------------------------+
| DB_INDEX_QFQ | DB_INDEX_QFQ = 1 | Optional. Default: 1. |
+-----------------------------+-------------------------------------------------+----------------------------------------------------------------------------+
| SQL_LOG | SQL_LOG=sql.log | Filename to log SQL commands: relative to <ext_dir> or absolute. |
| SQL_LOG | SQL_LOG=../../sql.log | Filename to log SQL commands: relative to <ext_dir> or absolute. |
+-----------------------------+-------------------------------------------------+----------------------------------------------------------------------------+
| SQL_LOG_MODE | SQL_LOG_MODE=modify | *all*: every statement will be logged - this might a lot. |
| | | *modify*: log only statements who change data. |
+-----------------------------+-------------------------------------------------+----------------------------------------------------------------------------+
| MAIL_LOG | SQL_LOG=../../mail.log | Filename to log `sendEmail` commands: relative to <ext_dir> or absolute. |
+-----------------------------+-------------------------------------------------+----------------------------------------------------------------------------+
| SEND_E_MAIL_OPTIONS | SEND_E_MAIL_OPTIONS="-o tls=yes" | General options. Check: http://caspian.dotconf.net/menu/Software/SendEmail |
+-----------------------------+-------------------------------------------------+----------------------------------------------------------------------------+
| SHOW_DEBUG_INFO | SHOW_DEBUG_INFO=auto | FE - Possible values: yes|no|auto|download. For 'auto': If a BE User is |
| | | logged in, a debug information will be shown on the FE. |
+-----------------------------+-------------------------------------------------+----------------------------------------------------------------------------+
......@@ -3357,6 +3361,8 @@ Type: sendmail
* *sendMailFrom* - Sender of the email. Optional: 'realname <john@doe.com>'. **Mandatory**.
* *sendMailSubject* - Subject of the email.
* *sendMailReplyTo* - Reply this email address. Optional: 'realname <john@doe.com>'.
* *sendMailAttachment* - List of files to attach to the mail. Multiple files separated by comma.
* *sendMailHeader* - Specify custom header.
* *sendMailFlagAutoSubmit* - **on|off** - If 'on' (default), the mail contains the header
'Auto-Submitted: auto-send' - this suppress a) OoO replies, b) forwarding of emails.
* *sendMailGrId* - Will be copied to the mailLog record. Helps to setup specific logfile queries.
......@@ -5224,59 +5230,59 @@ Send text emails. Every mail will be logged in the table `mailLog`.
::
SELECT "t:john@doe.com|f:jane@doe.com|s:Reminder tomorrow|b:Please dont miss the meeting tomorrow" AS _sendmail
SELECT "t:john@doe.com|f:jane@doe.com|s:Reminder tomorrow|b:Please dont miss the meeting tomorrow|a:off|g:1|x:2|y:3|z:4" AS _sendmail
SELECT "t:john@doe.com|f:jane@doe.com|s:Reminder tomorrow|b:Please dont miss the meeting tomorrow|A:off|g:1|x:2|y:3|z:4" AS _sendmail
..
+------------------------------------------------------------+------------------------------------------------------------------------------------------+------------+
|***Token** | **Parameter** |**Description** |**Required**|
+============================================================+==========================================================================================+============+
| t | email[,email] |Comma-separated list of receiver email addresses. Optional: `realname <john@doe.com>` | yes |
+------------------------------------------------------------+------------------------------------------------------------------------------------------+------------+
| f | FROM:email |Sender of the email. Optional: 'realname <john@doe.com>' | yes |
+------------------------------------------------------------+------------------------------------------------------------------------------------------+------------+
| s | subject |Subject of the email | yes |
+------------------------------------------------------------+------------------------------------------------------------------------------------------+------------+
| b | body |Message | yes |
+------------------------------------------------------------+------------------------------------------------------------------------------------------+------------+
| F | REPLY-TO:email |Email address to reply to (if different from sender) | |
+------------------------------------------------------------+------------------------------------------------------------------------------------------+------------+
| a | flagAutoSubmit 'on' / 'off' |If 'on' (default), add mail header 'Auto-Submitted: auto-send' - suppress OoO replies | |
+------------------------------------------------------------+------------------------------------------------------------------------------------------+------------+
| g | grId |Will be copied to the mailLog record. Helps to setup specific logfile queries | |
+------------------------------------------------------------+------------------------------------------------------------------------------------------+------------+
| x | xId |Will be copied to the mailLog record. Helps to setup specific logfile queries | |
+------------------------------------------------------------+------------------------------------------------------------------------------------------+------------+
| y | xId2 |Will be copied to the mailLog record. Helps to setup specific logfile queries | |
+------------------------------------------------------------+------------------------------------------------------------------------------------------+------------+
| z | xId3 |Will be copied to the mailLog record. Helps to setup specific logfile queries | |
+------------------------------------------------------------+------------------------------------------------------------------------------------------+------------+
| c | email[,email] |Comma-separated list of receiver email addresses. Optional: 'realname <john@doe.com>' | |
+------------------------------------------------------------+------------------------------------------------------------------------------------------+------------+
| B | mail[,email] |Comma-separated list of receiver email addresses. Optional: 'realname <john@doe.com>' | |
+------------------------------------------------------------+------------------------------------------------------------------------------------------+------------+
+---+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
|***Token** | **Parameter** |**Description** |**Required**|
+===+========================================+==================================================================================================+============+
| f | FROM:email |**FROM**: Sender of the email. Optional: 'realname <john@doe.com>' | yes |
+---+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| t | email[,email] |**TO**: Comma separated list of receiver email addresses. Optional: `realname <john@doe.com>` | yes |
+---+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| c | email[,email] |**CC**: Comma separated list of receiver email addresses. Optional: 'realname <john@doe.com>' | |
+---+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| B | email[,email] |**BCC**: Comma separated list of receiver email addresses. Optional: 'realname <john@doe.com>' | |
+---+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| r | REPLY-TO:email |**Reply-to**: Email address to reply to (if different from sender) | |
+---+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| s | Subject |**Subject**: Subject of the email | yes |
+---+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| b | Body |**Body**: Message | yes |
+---+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| h | Header |**Custom Header**: Separate multiple header with \r\n | |
+---+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| a | Attachment |**Attachment**: Comma separated list of filenames to attach to the mail | |
+---+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| A | flagAutoSubmit 'on' / 'off' |If 'on' (default), add mail header 'Auto-Submitted: auto-send' - suppress OoO replies | |
+---+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| g | grId |Will be copied to the mailLog record. Helps to setup specific logfile queries | |
+---+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| x | xId |Will be copied to the mailLog record. Helps to setup specific logfile queries | |
+---+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| y | xId2 |Will be copied to the mailLog record. Helps to setup specific logfile queries | |
+---+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
| z | xId3 |Will be copied to the mailLog record. Helps to setup specific logfile queries | |
+---+----------------------------------------+--------------------------------------------------------------------------------------------------+------------+
**Minimal Example**
::
10.sql = SELECT "john.doe@example.com|company@example.com|Latest News|The new version is now available." AS _sendmail
10.sql = SELECT "t:john.doe@example.com|f:company@example.com|s:Latest News|b:The new version is now available." AS _sendmail
..
This will send an email with subject *Latest News* from company@example.com to john.doe@example.com.
**Advanced Examples**
::
10.sql = SELECT "customer1@example.com,Firstname Lastname <customer2@example.com>, Firstname Lastname <customer3@example.com>|company@example.com|Latest News|The new version is now available.|sales@example.com|on|101|222|ceo@example.com|backup@example.com" AS _sendmail
10.sql = SELECT "t:customer1@example.com,Firstname Lastname <customer2@example.com>, Firstname Lastname <customer3@example.com>|
f:company@example.com|s:Latest News|b:The new version is now available.|r:sales@example.com|A:on|g:101|x:222|c:ceo@example.com|B:backup@example.com" AS _sendmail
..
This will send an email with subject *Latest News* from company@example.com to customer1, customer2 and customer3 by
......
......@@ -23,6 +23,9 @@ SQL_LOG = ../../sql.log
; all|modify|error|none
SQL_LOG_MODE = modify
;MAIL_LOG = ../../mail.log
;SEND_E_MAIL_OPTIONS = "-o ... " - check http://caspian.dotconf.net/menu/Software/SendEmail
; [auto|yes|no][,download]. 'auto': if BE User is logged in the value will be replaced by 'yes', else 'no'. Additional choose 'download'.
SHOW_DEBUG_INFO = auto
......
This diff is collapsed.
......@@ -374,6 +374,8 @@ const SYSTEM_SQL_LOG_FILE = '../../sql.log';
const SYSTEM_SQL_LOG_MODE = 'SQL_LOG_MODE'; // Mode, which statements to log.
const SYSTEM_DATE_FORMAT = 'DATE_FORMAT';
const SYSTEM_REDIRECT_ALL_MAIL_TO = 'REDIRECT_ALL_MAIL_TO';
const SYSTEM_MAIL_LOG = 'MAIL_LOG';
const SYSTEM_MAIL_LOG_FILE = '../../mail.log';
const SYSTEM_SHOW_DEBUG_INFO = 'SHOW_DEBUG_INFO';
const SYSTEM_SHOW_DEBUG_INFO_YES = 'yes';
......@@ -405,6 +407,9 @@ const SYSTEM_FORM_BUTTON_ON_CHANGE_CLASS = 'FORM_BUTTON_ON_CHANGE_CLASS';
const SYSTEM_BASE_URL_PRINT = 'BASE_URL_PRINT';
const SYSTEM_WKHTMLTOPDF = 'WKHTMLTOPDF';
const SYSTEM_SEND_E_MAIL = 'sendEmail';
const SYSTEM_SEND_E_MAIL_OPTIONS = 'SEND_E_MAIL_OPTIONS';
const SYSTEM_EDIT_FORM_PAGE = 'EDIT_FORM_PAGE';
// computed automatically during runtime
......@@ -912,7 +917,6 @@ const FE_INPUT_EXTRA_BUTTON_PASSWORD = 'extraButtonPassword';
const FE_INPUT_EXTRA_BUTTON_INFO = 'extraButtonInfo';
const FE_INPUT_EXTRA_BUTTON_INFO_CLASS = 'extraButtonInfoClass';
const FE_TMP_EXTRA_BUTTON_HTML = '_extraButtonHtml'; // will be filled on the fly during building extrabutton
const FE_TMP_EXTRA_BUTTON_HTML = '_extraButtonHtml'; // will be filled on the fly during building extrabutton
const FE_CHECKBOX_CHECKED = 'checked';
const FE_CHECKBOX_UNCHECKED = 'unchecked';
const FE_RECORD_DESTINATION_TABLE = 'recordDestinationTable';
......@@ -1059,20 +1063,24 @@ const SENDMAIL_IDX_GR_ID = 6;
const SENDMAIL_IDX_X_ID = 7;
const SENDMAIL_IDX_RECEIVER_CC = 8;
const SENDMAIL_IDX_RECEIVER_BCC = 9;
const SENDMAIL_IDX_X_ID2 = 10;
const SENDMAIL_IDX_X_ID3 = 11;
const SENDMAIL_IDX_SRC = 12;
const SENDMAIL_IDX_ATTACHMENT = 10;
const SENDMAIL_IDX_HEADER = 11;
const SENDMAIL_IDX_X_ID2 = 12;
const SENDMAIL_IDX_X_ID3 = 13;
const SENDMAIL_IDX_SRC = 14;
const SENDMAIL_TOKEN_RECEIVER = 't';
const SENDMAIL_TOKEN_SENDER = 'f';
const SENDMAIL_TOKEN_SUBJECT = 's';
const SENDMAIL_TOKEN_BODY = 'b';
const SENDMAIL_TOKEN_REPLY_TO = 'F';
const SENDMAIL_TOKEN_FLAG_AUTO_SUBMIT = 'a';
const SENDMAIL_TOKEN_REPLY_TO = 'r';
const SENDMAIL_TOKEN_FLAG_AUTO_SUBMIT = 'A';
const SENDMAIL_TOKEN_GR_ID = 'g';
const SENDMAIL_TOKEN_X_ID = 'x';
const SENDMAIL_TOKEN_RECEIVER_CC = 'c';
const SENDMAIL_TOKEN_RECEIVER_BCC = 'B';
const SENDMAIL_TOKEN_ATTACHMENT = 'a';
const SENDMAIL_TOKEN_HEADER = 'h';
const SENDMAIL_TOKEN_X_ID2 = 'y';
const SENDMAIL_TOKEN_X_ID3 = 'z';
const SENDMAIL_TOKEN_SRC = 'S';
......
......@@ -706,36 +706,36 @@ class Report {
break;
}
$mailarr = explode("|", $columnValue, 3);
$mailConfig = explode("|", $columnValue, 3);
// Fake values for tmp[1], tmp[2] to suppress access errors.
$mailarr[] = '';
$mailarr[] = '';
$mailConfig[] = '';
$mailConfig[] = '';
if (empty($mailarr[0])) {
if (empty($mailConfig[0])) {
break;
}
$attribute = Support::doAttribute('src', $mailarr[0]);
$attribute .= Support::doAttribute('alt', $mailarr[1]);
$attribute = Support::doAttribute('src', $mailConfig[0]);
$attribute .= Support::doAttribute('alt', $mailConfig[1]);
$content .= '<img ' . $attribute . '>' . $mailarr[2];
$content .= '<img ' . $attribute . '>' . $mailConfig[2];
break;
case "mailto":
// "<email address>|[Real Name]" renders to (encrypted via JS): <a href="mailto://<email address>"><email address></a> OR <a href="mailto://<email address>">[Real Name]</a>
$mailarr = explode("|", $columnValue, 2);
if (empty($mailarr[0])) {
$mailConfig = explode("|", $columnValue, 2);
if (empty($mailConfig[0])) {
break;
}
$t1 = explode("@", $mailarr[0], 2);
$t1 = explode("@", $mailConfig[0], 2);
$content .= "<script language=javascript><!--" . chr(10);
if (empty($mailarr[1])) {
$mailarr[1] = $mailarr[0];
if (empty($mailConfig[1])) {
$mailConfig[1] = $mailConfig[0];
}
$content .= 'var contact = "' . substr($mailarr[1], 0, 2) . '"' . chr(10);
$content .= 'var contact1 = "' . substr($mailarr[1], 2) . '"' . chr(10);
$content .= 'var contact = "' . substr($mailConfig[1], 0, 2) . '"' . chr(10);
$content .= 'var contact1 = "' . substr($mailConfig[1], 2) . '"' . chr(10);
$content .= 'var email = "' . $t1[0] . '"' . chr(10);
$content .= 'var emailHost = "' . $t1[1] . '"' . chr(10);
......@@ -747,56 +747,56 @@ class Report {
case "sendmail":
// '<receiver1>,<receiver2>,...|<sender>|<subject>|<body>|<reply-to>|<flag autosubmit: on /off>'
// $mailarr = explode("|", $columnValue);
$mailarr = $this->sendmailConvertToken($columnValue);
if (count($mailarr) < 4) {
$mailConfig = $this->sendmailConvertToken($columnValue);
if (count($mailConfig) < 4) {
throw new SyntaxReportException ("Too few parameter for sendmail: $columnValue", ERROR_TOO_FEW_PARAMETER_FOR_SENDMAIL, null, __FILE__, __LINE__, $this->fr_error);
}
if (!isset($mailarr[SENDMAIL_IDX_REPLY_TO])) {
$mailarr[SENDMAIL_IDX_REPLY_TO] = '';
}
if (!isset($mailarr[SENDMAIL_IDX_FLAG_AUTO_SUBMIT])) {
$mailarr[SENDMAIL_IDX_FLAG_AUTO_SUBMIT] = 'on';
}
if (!isset($mailarr[SENDMAIL_IDX_GR_ID])) {
$mailarr[SENDMAIL_IDX_GR_ID] = '0';
}
if (!isset($mailarr[SENDMAIL_IDX_X_ID])) {
$mailarr[SENDMAIL_IDX_X_ID] = '0';
}
if (!isset($mailarr[SENDMAIL_IDX_RECEIVER_CC])) {
$mailarr[SENDMAIL_IDX_RECEIVER_CC] = '';
}
if (!isset($mailarr[SENDMAIL_IDX_RECEIVER_BCC])) {
$mailarr[SENDMAIL_IDX_RECEIVER_BCC] = '';
}
if (!isset($mailarr[SENDMAIL_IDX_X_ID])) {
$mailarr[SENDMAIL_IDX_X_ID] = '0';
}
if (!isset($mailarr[SENDMAIL_IDX_X_ID2])) {
$mailarr[SENDMAIL_IDX_X_ID] = '0';
}
if (!isset($mailarr[SENDMAIL_IDX_X_ID3])) {
$mailarr[SENDMAIL_IDX_X_ID] = '0';
}
$mailarr[SENDMAIL_IDX_SRC] = "Report: T3 pageId=" . $this->store->getVar('pageId', STORE_TYPO3) .
// if (!isset($mailarr[SENDMAIL_IDX_REPLY_TO])) {
// $mailarr[SENDMAIL_IDX_REPLY_TO] = '';
// }
//
// if (!isset($mailarr[SENDMAIL_IDX_FLAG_AUTO_SUBMIT])) {
// $mailarr[SENDMAIL_IDX_FLAG_AUTO_SUBMIT] = 'on';
// }
//
// if (!isset($mailarr[SENDMAIL_IDX_GR_ID])) {
// $mailarr[SENDMAIL_IDX_GR_ID] = '0';
// }
//
// if (!isset($mailarr[SENDMAIL_IDX_X_ID])) {
// $mailarr[SENDMAIL_IDX_X_ID] = '0';
// }
//
// if (!isset($mailarr[SENDMAIL_IDX_RECEIVER_CC])) {
// $mailarr[SENDMAIL_IDX_RECEIVER_CC] = '';
// }
//
// if (!isset($mailarr[SENDMAIL_IDX_RECEIVER_BCC])) {
// $mailarr[SENDMAIL_IDX_RECEIVER_BCC] = '';
// }
//
// if (!isset($mailarr[SENDMAIL_IDX_X_ID])) {
// $mailarr[SENDMAIL_IDX_X_ID] = '0';
// }
//
// if (!isset($mailarr[SENDMAIL_IDX_X_ID2])) {
// $mailarr[SENDMAIL_IDX_X_ID] = '0';
// }
//
// if (!isset($mailarr[SENDMAIL_IDX_X_ID3])) {
// $mailarr[SENDMAIL_IDX_X_ID] = '0';
// }
$mailConfig[SENDMAIL_IDX_SRC] = "Report: T3 pageId=" . $this->store->getVar('pageId', STORE_TYPO3) .
", T3 ttcontentId=" . $this->store->getVar('ttcontentUid', STORE_TYPO3) .
", Level=" . $full_level;
new Sendmail($mailarr);
new Sendmail($mailConfig);
break;
case "vertical":
// '<Text>|[angle]|[width]|[height]|[tag]' , width and heigth needs a unit (px, em ,...), 'tag' might be 'div', 'span', ...
// '<Text>|[angle]|[width]|[height]|[tag]' , width and height needs a unit (px, em ,...), 'tag' might be 'div', 'span', ...
$arr = explode("|", $columnValue, 5);
# angle
......@@ -804,11 +804,11 @@ class Report {
# width
$width = $arr[2] ? $arr[2] : "1em";
$mailarr = "width:$width; ";
$extra = "width:$width; ";
# height
if ($arr[3]) {
$mailarr .= "height:" . $arr[3] . "; ";
$extra .= "height:" . $arr[3] . "; ";
}
# tag
......@@ -864,7 +864,7 @@ class Report {
exec($cmd, $arr, $rc);
$output = implode('<BR>', $arr);
$output = implode('<br>', $arr);
if ($rc != 0) {
$output = $rc . " - " . $output;
}
......@@ -1251,11 +1251,13 @@ class Report {
SENDMAIL_TOKEN_SUBJECT => SENDMAIL_IDX_SUBJECT,
SENDMAIL_TOKEN_BODY => SENDMAIL_IDX_BODY,
SENDMAIL_TOKEN_REPLY_TO => SENDMAIL_IDX_REPLY_TO,
SENDMAIL_TOKEN_RECEIVER_CC => SENDMAIL_IDX_RECEIVER_CC,
SENDMAIL_TOKEN_RECEIVER_BCC => SENDMAIL_IDX_RECEIVER_BCC,
SENDMAIL_TOKEN_HEADER => SENDMAIL_IDX_HEADER,
SENDMAIL_TOKEN_ATTACHMENT => SENDMAIL_IDX_ATTACHMENT,
SENDMAIL_TOKEN_FLAG_AUTO_SUBMIT => SENDMAIL_IDX_FLAG_AUTO_SUBMIT,
SENDMAIL_TOKEN_GR_ID => SENDMAIL_IDX_GR_ID,
SENDMAIL_TOKEN_X_ID => SENDMAIL_IDX_X_ID,
SENDMAIL_TOKEN_RECEIVER_CC => SENDMAIL_IDX_RECEIVER_CC,
SENDMAIL_TOKEN_RECEIVER_BCC => SENDMAIL_IDX_RECEIVER_BCC,
SENDMAIL_TOKEN_SRC => SENDMAIL_IDX_SRC,
SENDMAIL_TOKEN_X_ID2 => SENDMAIL_IDX_X_ID2,
SENDMAIL_TOKEN_X_ID3 => SENDMAIL_IDX_X_ID3
......@@ -1267,7 +1269,7 @@ class Report {
}
$segments = explode('|', $data);
$arr = ['', '', '', '', '', '', '', '', '', '', '', '', ''];
$arr = ['', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', ''];
foreach ($segments AS $line) {
$piece = explode(':', $line, 2);
......
......@@ -11,6 +11,11 @@ require_once(__DIR__ . '/../store/Store.php');
class Sendmail {
/**
* @var Store
*/
private $store = null;
/**
* Sends a mail as specified in $mailarr.
* If there is no receiver specified as 'TO': no mail is sent. This is ok and no error.
......@@ -28,71 +33,169 @@ class Sendmail {
* SENDMAIL_IDX_GR_ID optional: integer
* SENDMAIL_IDX_X_ID optional: integer
*
* @param $mailarr
* @param $mailConfig
*
* @throws UserFormException
*/
public function __construct(array $mailarr) {
$addBody = '';
public function __construct(array $mailConfig) {
// If there is no 'Receiver': do not send a mail.
if (!isset($mailarr[SENDMAIL_IDX_RECEIVER]) || $mailarr[SENDMAIL_IDX_RECEIVER] === '') {
if (!isset($mailConfig[SENDMAIL_IDX_RECEIVER]) || $mailConfig[SENDMAIL_IDX_RECEIVER] === '') {
return;
}
if (count($mailarr) < 4 || $mailarr[SENDMAIL_IDX_SENDER] === '' || $mailarr[SENDMAIL_IDX_SUBJECT] === '' || $mailarr[SENDMAIL_IDX_BODY] === '') {
if (count($mailConfig) < 4 || $mailConfig[SENDMAIL_IDX_SENDER] === '' || $mailConfig[SENDMAIL_IDX_SUBJECT] === '' || $mailConfig[SENDMAIL_IDX_BODY] === '') {
throw new UserFormException("Error sendmail missing one of: receiver, sender, subject or body", ERROR_SENDMAIL_MISSING_VALUE);
}
$store = Store::getInstance('');
$redirectAllMail = $store->getVar(SYSTEM_REDIRECT_ALL_MAIL_TO, STORE_SYSTEM);
$this->store = Store::getInstance('');
$redirectAllMail = $this->store->getVar(SYSTEM_REDIRECT_ALL_MAIL_TO, STORE_SYSTEM);
if ($redirectAllMail !== false) {
$addBody .= "All QFQ outgoing mails are catched and redirected to you." . PHP_EOL . "Original receiver:" . PHP_EOL;
$addBody .= 'TO: ' . $mailarr[SENDMAIL_IDX_RECEIVER] . PHP_EOL;
$addBody .= 'CC: ' . $mailarr[SENDMAIL_IDX_RECEIVER_CC] . PHP_EOL;
$addBody .= 'BCC: ' . $mailarr[SENDMAIL_IDX_RECEIVER_BCC] . PHP_EOL;
$addBody = "All QFQ outgoing mails are catched and redirected to you." . PHP_EOL . "Original receiver:" . PHP_EOL;
$addBody .= 'TO: ' . $mailConfig[SENDMAIL_IDX_RECEIVER] . PHP_EOL;
$addBody .= 'CC: ' . $mailConfig[SENDMAIL_IDX_RECEIVER_CC] . PHP_EOL;
$addBody .= 'BCC: ' . $mailConfig[SENDMAIL_IDX_RECEIVER_BCC] . PHP_EOL;
$addBody .= PHP_EOL . "==========================================" . PHP_EOL . PHP_EOL;
$mailarr[SENDMAIL_IDX_RECEIVER] = $redirectAllMail;
$mailarr[SENDMAIL_IDX_RECEIVER_CC] = '';
$mailarr[SENDMAIL_IDX_RECEIVER_BCC] = '';
$mailConfig[SENDMAIL_IDX_BODY] = $addBody . $mailConfig[SENDMAIL_IDX_BODY];
$mailConfig[SENDMAIL_IDX_RECEIVER] = $redirectAllMail;
$mailConfig[SENDMAIL_IDX_RECEIVER_CC] = '';
$mailConfig[SENDMAIL_IDX_RECEIVER_BCC] = '';
}
if (empty($mailConfig[SENDMAIL_IDX_FLAG_AUTO_SUBMIT]) || $mailConfig[SENDMAIL_IDX_FLAG_AUTO_SUBMIT] === '') {
$mailConfig[SENDMAIL_IDX_FLAG_AUTO_SUBMIT] = 'on';
}
$header = $this->buildHeader($mailarr);
// $header = $this->buildHeader($mailarr);
// if (!(mb_send_mail($mailarr[SENDMAIL_IDX_RECEIVER], $mailarr[SENDMAIL_IDX_SUBJECT], $addBody . $mailarr[SENDMAIL_IDX_BODY], $header, "-f " . $mailarr[SENDMAIL_IDX_SENDER]))) {
// throw new UserFormException("Error sendmail failed.", ERROR_SENDMAIL);
// }
if (!(mb_send_mail($mailarr[SENDMAIL_IDX_RECEIVER], $mailarr[SENDMAIL_IDX_SUBJECT], $addBody . $mailarr[SENDMAIL_IDX_BODY], $header, "-f " . $mailarr[SENDMAIL_IDX_SENDER]))) {
throw new UserFormException("Error sendmail failed.", ERROR_SENDMAIL);
$this->sendEmail($mailConfig);
$this->mailLog($mailConfig);
}
/**
* Use the programm 'sendEmail' - http://caspian.dotconf.net/menu/Software/SendEmail
*
* @param array $mailConfig
* @throws CodeException
* @throws UserFormException
*/
private function sendEmail(array $mailConfig) {
$args = array();
foreach ($mailConfig as $key => $value) {
$mailConfig[$key] = Support::escapeDoubleTick($value);
}
$this->mailLog($mailarr, $header);
$args[] = '-f "' . $mailConfig[SENDMAIL_IDX_SENDER] . '"';
$args[] = '-t "' . $mailConfig[SENDMAIL_IDX_RECEIVER] . '"';
$args[] = '-o message-charset="utf-8"';
$args[] = '-q ';
$logFile = $this->store->getVar(SYSTEM_MAIL_LOG, STORE_SYSTEM);
if ($logFile != '' && $logFile !== false) {
$args[] = '-l "' . $logFile . '"';;
}
if (!empty($mailConfig[SENDMAIL_IDX_RECEIVER_CC])) {
$args[] = '-cc "' . $mailConfig[SENDMAIL_IDX_RECEIVER_CC] . '"';;
}
if (!empty($mailConfig[SENDMAIL_IDX_RECEIVER_BCC])) {
$args[] = '-bcc "' . $mailConfig[SENDMAIL_IDX_RECEIVER_BCC];
}
if (!empty($mailConfig[SENDMAIL_IDX_SUBJECT])) {
// The subject needs to be encoded to UTF-8 separately - https://stackoverflow.com/questions/4389676/email-from-php-has-broken-subject-header-encoding/27648245#27648245
$preferences = ["scheme" => "Q", "input-charset" => "UTF-8", "output-charset" => "UTF-8"];
$encodedSubject = iconv_mime_encode("Subject", $mailConfig[SENDMAIL_IDX_SUBJECT], $preferences);
$encodedSubject = substr($encodedSubject, 9); // remove 'Subject: '
$args[] = '-u "' . $encodedSubject . '"';;
}
if (!empty($mailConfig[SENDMAIL_IDX_BODY])) {
$args[] = '-m "' . $mailConfig[SENDMAIL_IDX_BODY] . '"';;
}
if (!empty($mailConfig[SENDMAIL_IDX_REPLY_TO])) {
$args[] = '-o reply-to="' . $mailConfig[SENDMAIL_IDX_REPLY_TO] . '"';;
}
if ($mailConfig[SENDMAIL_IDX_FLAG_AUTO_SUBMIT] === 'on') {
$args[] = '-o message-header="Auto-Submitted: auto-send"';
}
if (!empty($mailConfig[SENDMAIL_IDX_ATTACHMENT])) {
$pieces = explode(',', $mailConfig[SENDMAIL_IDX_ATTACHMENT]);
foreach ($pieces as $piece) {
$args[] = '-a ' . $piece;
}
}
if (!empty($mailConfig[SENDMAIL_IDX_HEADER])) {
$args[] = '-o message-header="' . $mailConfig[SENDMAIL_IDX_HEADER] . '"';
}
$sendEmail = $this->store->getVar(SYSTEM_SEND_E_MAIL, STORE_SYSTEM);
if (empty($sendEmail)) {
throw new UserFormException("Missing 'sendEmail'", ERROR_SENDMAIL);
}
$sendEmailOptions = $this->store->getVar(SYSTEM_SEND_E_MAIL_OPTIONS, STORE_SYSTEM);
if (!empty($sendEmailOptions)) {
$args[] = $sendEmailOptions;
}
$cmd = $sendEmail . ' ' . implode(' ', $args);
exec($cmd, $arr, $rc);
if ($rc != 0) {
// After first installation of QFQ extension, the PERL script is not executable: is this the case?
$perms = fileperms($sendEmail);
if (!($perms & 0x0040)) {
chmod($sendEmail, 0755);
exec($cmd, $arr, $rc); // Give it a second try.
}
if ($rc != 0) {
$output = $rc . " - " . implode('<br>', $arr);
throw new UserFormException("Error sendmail failed: " . $output, ERROR_SENDMAIL);
}
}
}
/**
* @param array $mailarr
* @param array $mailConfig
*
* @return string
*/
private function buildHeader(array $mailarr) {
private function buildHeader(array $mailConfig) {
// "\r\n" needs to be enclosed in double ticks to correctly converted to 0x0d 0x0a,
$header = "From: " . $mailarr[SENDMAIL_IDX_SENDER] . "\r\n";
$header = "From: " . $mailConfig[SENDMAIL_IDX_SENDER] . "\r\n";
if (isset($mailarr[SENDMAIL_IDX_REPLY_TO]) && $mailarr[SENDMAIL_IDX_REPLY_TO] != '') {
$header .= "Reply-To: " . $mailarr[SENDMAIL_IDX_REPLY_TO] . "\r\n";
if (isset($mailConfig[SENDMAIL_IDX_REPLY_TO]) && $mailConfig[SENDMAIL_IDX_REPLY_TO] != '') {
$header .= "Reply-To: " . $mailConfig[SENDMAIL_IDX_REPLY_TO] . "\r\n";
}
// By default 'on'
if (!isset($mailarr[SENDMAIL_IDX_FLAG_AUTO_SUBMIT]) || $mailarr[SENDMAIL_IDX_FLAG_AUTO_SUBMIT] === 'on') {
if (!isset($mailConfig[SENDMAIL_IDX_FLAG_AUTO_SUBMIT]) || $mailConfig[SENDMAIL_IDX_FLAG_AUTO_SUBMIT] === 'on') {
$header .= "Auto-Submitted: auto-send\r\n";
}
if (isset($mailarr[SENDMAIL_IDX_RECEIVER_CC]) && $mailarr[SENDMAIL_IDX_RECEIVER_CC] != '') {
$header .= "Cc: " . $mailarr[SENDMAIL_IDX_RECEIVER_CC] . "\r\n";
if (isset($mailConfig[SENDMAIL_IDX_RECEIVER_CC]) && $mailConfig[SENDMAIL_IDX_RECEIVER_CC] != '') {
$header .= "Cc: " . $mailConfig[SENDMAIL_IDX_RECEIVER_CC] . "\r\n";
}