diff --git a/application/Espo/Core/Mail/Sender.php b/application/Espo/Core/Mail/Sender.php
index ad92ad15c7..5a1d90105e 100644
--- a/application/Espo/Core/Mail/Sender.php
+++ b/application/Espo/Core/Mail/Sender.php
@@ -201,23 +201,21 @@ class Sender
$body = new MimeMessage;
$parts = array();
-
+
+ $bodyPart = new MimePart($email->getBodyPlainForSending());
+ $bodyPart->type = 'text/plain';
+ $bodyPart->charset = 'utf-8';
+ $parts[] = $bodyPart;
+
+
if ($email->get('isHtml')) {
$bodyPart = new MimePart($email->getBodyForSending());
$bodyPart->type = 'text/html';
$bodyPart->charset = 'utf-8';
- } else {
- if ($email->get('bodyPlain')) {
- $bodyPart = new MimePart($email->get('bodyPlain'));
- } else {
- $bodyPart = new MimePart($email->get('body'));
- }
- $bodyPart->type = 'text/plain';
- $bodyPart->charset = 'utf-8';
+ $parts[] = $bodyPart;
}
-
- $parts[] = $bodyPart;
+
$aCollection = $email->get('attachments');
if (!empty($aCollection)) {
@@ -251,6 +249,10 @@ class Sender
$body->setParts($parts);
$message->setBody($body);
+
+ if ($email->get('isHtml')) {
+ $message->getHeaders()->get('content-type')->setType('multipart/alternative');
+ }
try {
$this->transport->send($message);
diff --git a/application/Espo/Entities/Email.php b/application/Espo/Entities/Email.php
index 6f2e144397..1139f45b50 100644
--- a/application/Espo/Entities/Email.php
+++ b/application/Espo/Entities/Email.php
@@ -46,6 +46,21 @@ class Email extends \Espo\Core\ORM\Entity
}
}
+ public function getBodyPlainForSending()
+ {
+ $bodyPlain = $this->get('bodyPlain');
+ if (!empty($bodyPlain)) {
+ return $bodyPlain;
+ }
+
+ $body = $this->get('body');
+
+ $breaks = array("
","
","
","
","<br />","<br/>","<br>");
+ $body = str_ireplace($breaks, "\r\n", $body);
+ $body = strip_tags($body);
+ return $body;
+ }
+
public function getBodyForSending()
{
$body = $this->get('body');
@@ -55,6 +70,7 @@ class Email extends \Espo\Core\ORM\Entity
$body = str_replace("?entryPoint=attachment&id={$attachment->id}", "cid:{$attachment->id}", $body);
}
}
+
$body = str_replace("