Merge pull request #23215 from eileenmcnaughton/test_amount
[civicrm-core.git] / CRM / Utils / Mail.php
index 2043f9494dfb6f58cbbd9d46e8737700444e1bd0..beb0ad3263b8116ebcb3515a4a3b34097a778358 100644 (file)
@@ -159,6 +159,7 @@ class CRM_Utils_Mail {
    *   fullPath : complete pathname to the file
    *   mime_type: mime type of the attachment
    *   cleanName: the user friendly name of the attachmment
+   * contactId : contact id to send the email to (optional)
    *
    * @param array $params
    *   (by reference).
@@ -183,14 +184,20 @@ class CRM_Utils_Mail {
       return FALSE;
     }
 
-    $textMessage = $params['text'] ?? NULL;
-    $htmlMessage = $params['html'] ?? NULL;
-    $attachments = $params['attachments'] ?? NULL;
-
-    // CRM-6224
-    if (trim(CRM_Utils_String::htmlToText($htmlMessage)) == '') {
+    $htmlMessage = $params['html'] ?? FALSE;
+    if (trim(CRM_Utils_String::htmlToText((string) $htmlMessage)) === '') {
       $htmlMessage = FALSE;
     }
+    $attachments = $params['attachments'] ?? NULL;
+    if (!empty($params['text'])) {
+      $textMessage = $params['text'];
+    }
+    else {
+      $textMessage = CRM_Utils_String::htmlToText($htmlMessage);
+      // Render the & entities in text mode, so that the links work.
+      // This is copied from the Action Schedule send code.
+      $textMessage = str_replace('&', '&', $textMessage);
+    }
 
     $headers = [];
     // CRM-10699 support custom email headers
@@ -436,7 +443,7 @@ class CRM_Utils_Mail {
 
   /**
    * @param string $name
-   * @param $email
+   * @param string $email
    * @param bool $useQuote
    *
    * @return null|string