1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-31 11:50:30 +02:00

Closes #4924 - sendEmail() updated.

This commit is contained in:
Cameron
2022-12-15 22:11:05 -08:00
parent 5f84a8253e
commit bc6d371942
2 changed files with 47 additions and 11 deletions

View File

@@ -988,8 +988,17 @@ class e107Email extends PHPMailer
$identifier = deftrue('MAIL_IDENTIFIER', 'X-e107-id');
if (isset($eml['SMTPDebug'])) { $this->SMTPDebug = $eml['SMTPDebug']; } // 'false' is a valid value!
if (!empty($eml['sender_email'])) { $this->From = $eml['sender_email']; }
if (!empty($eml['sender_name'])) { $this->FromName = $eml['sender_name']; }
if (!empty($eml['sender_email']) && !empty($eml['sender_email']))
{
$this->setFrom($eml['sender_email'], $eml['sender_name']);
}
else
{
if (!empty($eml['sender_email'])) { $this->From = $eml['sender_email']; }
if (!empty($eml['sender_name'])) { $this->FromName = $eml['sender_name']; }
}
if (!empty($eml['replyto'])) { $this->AddAddressList('replyto',$eml['replyto'],vartrue($eml['replytonames'],'')); }
if (isset($eml['html'])) { $this->allow_html = $eml['html']; } // 'false' is a valid value!
if (isset($eml['html_header'])) { $this->add_HTML_header = $eml['html_header']; } // 'false' is a valid value!
@@ -1354,7 +1363,8 @@ class e107Email extends PHPMailer
$this->isHTML(true);
$this->Body = $message;
// $this->Body = $message;
$this->Body = static::normalizeBreaks($message);
//print_a($message);
$textMsg = str_replace("\n", "", $message);
$textMsg = str_replace('</td>', "\t", $textMsg);
@@ -1362,7 +1372,7 @@ class e107Email extends PHPMailer
$textMsg = str_replace(array('<br />', '<br>'), "\n", $textMsg); // Modified to make sure newlines carried through
$textMsg = preg_replace('#^.*?<body.*?>#', '', $textMsg); // Knock off everything up to and including the body statement (if present)
$textMsg = preg_replace('#</body.*?>.*$#', '', $textMsg); // Knock off everything after and including the </body> (if present)
$textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s','',$textMsg)));
// $textMsg = trim(strip_tags(preg_replace('/<(head|title|style|script)[^>]*>.*?<\/\\1>/s','',$textMsg)));
if($this->debug)
{
@@ -1372,8 +1382,7 @@ class e107Email extends PHPMailer
if(!empty($textMsg)) // Always set it, even if AltBody is empty.
{
$this->AltBody = html_entity_decode($textMsg);
$this->AltBody = static::normalizeBreaks($this->html2text($textMsg, $advanced));
}
if(empty($this->AltBody))

View File

@@ -132,10 +132,6 @@
}
public function testPreview()
{
}
public function testAddInlineImages()
{
@@ -164,7 +160,7 @@ Admin<br />
$this->eml->MsgHTML($html);
$result = json_encode($this->eml->AltBody);
$expected = '"Hi Joe\\nCheck out https:\\/\\/e107.org\\n\\nThanks,\\nAdmin\\n\\nWebsite:\\thttps:\\/\\/e107.org\\t\\nGithub:\\thttps:\\/\\/github.com\\/e107inc\\/"';
$expected = '"Hi Joe\r\nCheck out https:\/\/e107.org\r\n\r\nThanks,\r\nAdmin\r\n\r\nWebsite:\thttps:\/\/e107.org\t\r\nGithub:\thttps:\/\/github.com\/e107inc\/"';
$this->assertSame($expected, $result);
}
@@ -211,5 +207,36 @@ Admin<br />
*/
function testSentMimeMessage()
{
$eml = array(
'subject' => "[PREVIEW]",
'sender_email' => "noreply@test.com",
'sender_name' => "Test Person",
'replyto' => "someone@else.com",
'html' => true,
'priority' => 1,
// 'template' => 'default',
'body' => "Hi,<br />This is the <b>body</b> text",
'cc' => '',
'shortcodes' => [
'NAME' => "TestName",
'DATE' => 'Jan 1st, 2020'
],
);
$this->eml->arraySet($eml);
$this->eml->AddAddressList('to','recipient@example.com',"Example Recipient");
$this->eml->preSend();
$result = $this->eml->getSentMIMEMessage();
$this->assertStringContainsString('Content-Type: text/plain;', $result);
$this->assertStringContainsString('This is the body text', $result);
$this->assertStringContainsString('Content-Type: text/html;', $result);
$this->assertStringContainsString('Hi,<br />This is the <b>body</b> text', $result);
}
}