Create\Email fixes
Remove not needed reaplce content count for first global replace Move logger out of test only and log if a logger class is attached
This commit is contained in:
@@ -567,12 +567,6 @@ final class CoreLibsCreateEmailTest extends TestCase
|
|||||||
$email['body'] ?? '',
|
$email['body'] ?? '',
|
||||||
'Email check: assert body'
|
'Email check: assert body'
|
||||||
);
|
);
|
||||||
/*
|
|
||||||
[header] [From] => test@test.com
|
|
||||||
[to] => test@test.com
|
|
||||||
[subject] => SUBJECT
|
|
||||||
[body] => BODY
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -178,10 +178,7 @@ class Email
|
|||||||
// only if there is no dedicated to replace
|
// only if there is no dedicated to replace
|
||||||
// also run replace if there is nothing to replace at all
|
// also run replace if there is nothing to replace at all
|
||||||
// this will mime encode the subject
|
// this will mime encode the subject
|
||||||
if (
|
if (!count($to_replace)) {
|
||||||
!count($to_replace) &&
|
|
||||||
count($replace_content) || !count($replace_content)
|
|
||||||
) {
|
|
||||||
list($out_subject, $out_body) = self::replaceContent(
|
list($out_subject, $out_body) = self::replaceContent(
|
||||||
$subject,
|
$subject,
|
||||||
$body,
|
$body,
|
||||||
@@ -193,6 +190,7 @@ class Email
|
|||||||
$mail_delivery_status = 1;
|
$mail_delivery_status = 1;
|
||||||
// send the email
|
// send the email
|
||||||
foreach ($to_emails as $to_email) {
|
foreach ($to_emails as $to_email) {
|
||||||
|
// default mail status is success
|
||||||
$mail_status = true;
|
$mail_status = true;
|
||||||
// if there is a to replace, if not use the original replace content
|
// if there is a to replace, if not use the original replace content
|
||||||
if (count($to_replace)) {
|
if (count($to_replace)) {
|
||||||
@@ -211,29 +209,32 @@ class Email
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// if we are in test mode, do not send an email and set status to 2
|
||||||
if ($test === false) {
|
if ($test === false) {
|
||||||
$mail_status = mail($to_email, $out_subject, $out_body, $headers);
|
$mail_status = mail($to_email, $out_subject, $out_body, $headers);
|
||||||
} else {
|
} else {
|
||||||
if ($log instanceof \CoreLibs\Debug\Logging) {
|
|
||||||
// build debug strings: convert to UTF-8 if not utf-8
|
|
||||||
$log->debug('SEND EMAIL', 'HEADERS: ' . $log->prAr($headers) . ', '
|
|
||||||
. 'TO: ' . $to_email . ', '
|
|
||||||
. 'SUBJECT: ' . $out_subject . ', '
|
|
||||||
. 'BODY: ' . ($encoding == 'UTF-8' ?
|
|
||||||
$out_body :
|
|
||||||
mb_convert_encoding($out_body, 'UTF-8', $encoding)));
|
|
||||||
$log->debug('SEND EMAIL JSON', json_encode([
|
|
||||||
'encoding' => $encoding,
|
|
||||||
'header' => $headers,
|
|
||||||
'to' => $to_email,
|
|
||||||
'subject' => $out_subject,
|
|
||||||
'body' => ($encoding == 'UTF-8' ?
|
|
||||||
$out_body :
|
|
||||||
mb_convert_encoding($out_body, 'UTF-8', $encoding))
|
|
||||||
]) ?: '{}');
|
|
||||||
}
|
|
||||||
$mail_delivery_status = 2;
|
$mail_delivery_status = 2;
|
||||||
}
|
}
|
||||||
|
// log if an log instance exists
|
||||||
|
if ($log instanceof \CoreLibs\Debug\Logging) {
|
||||||
|
// build debug strings: convert to UTF-8 if not utf-8
|
||||||
|
$log->debug('SEND EMAIL', 'HEADERS: ' . $log->prAr($headers) . ', '
|
||||||
|
. 'ENCODING: ' . $encoding . ', '
|
||||||
|
. 'TO: ' . $to_email . ', '
|
||||||
|
. 'SUBJECT: ' . $out_subject . ', '
|
||||||
|
. 'BODY: ' . ($encoding == 'UTF-8' ?
|
||||||
|
$out_body :
|
||||||
|
mb_convert_encoding($out_body, 'UTF-8', $encoding)));
|
||||||
|
$log->debug('SEND EMAIL JSON', json_encode([
|
||||||
|
'encoding' => $encoding,
|
||||||
|
'header' => $headers,
|
||||||
|
'to' => $to_email,
|
||||||
|
'subject' => $out_subject,
|
||||||
|
'body' => ($encoding == 'UTF-8' ?
|
||||||
|
$out_body :
|
||||||
|
mb_convert_encoding($out_body, 'UTF-8', $encoding))
|
||||||
|
]) ?: '{}');
|
||||||
|
}
|
||||||
if (!$mail_status) {
|
if (!$mail_status) {
|
||||||
$mail_delivery_status = 0;
|
$mail_delivery_status = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user