diff --git a/core/lib/Drupal/Core/Mail/MailFormatHelper.php b/core/lib/Drupal/Core/Mail/MailFormatHelper.php
index 260174eca748b18030a88def694914c29ec30ffe..31762c501477b3692e4e9db8a2b82fdf13e64ed6 100644
--- a/core/lib/Drupal/Core/Mail/MailFormatHelper.php
+++ b/core/lib/Drupal/Core/Mail/MailFormatHelper.php
@@ -130,7 +130,7 @@ public static function htmlToText($string, $allowed_tags = NULL) {
     // 'See <a href="https://www.drupal.org">the Drupal site</a>' becomes
     // 'See the Drupal site [1]' with the URL included as a footnote.
     static::htmlToMailUrls(NULL, TRUE);
-    $pattern = '@(<a[^>]+?href="([^"]*)"[^>]*?>(.+?)</a>)@i';
+    $pattern = '@(<a[^>]+?href="([^"]*)"[^>]*?>([^<]*)</a>)@i';
     $string = preg_replace_callback($pattern, [static::class, 'htmlToMailUrls'], $string);
     $urls = static::htmlToMailUrls();
     $footnotes = '';
@@ -343,7 +343,8 @@ protected static function htmlToMailUrls($match = NULL, $reset = FALSE) {
         [, , $url, $label] = $match;
         // Ensure all URLs are absolute.
         static::$urls[] = strpos($url, '://') ? $url : preg_replace(static::$regexp, $base_url . '/', $url);
-        return $label . ' [' . count(static::$urls) . ']';
+        // Strip newlines and carriage returns from anchor text.
+        return preg_replace('/\r?\n|\r/', '', $label) . ' [' . count(static::$urls) . ']';
       }
     }
     return static::$urls;
diff --git a/core/modules/system/tests/src/Unit/Mail/HtmlToTextTest.php b/core/modules/system/tests/src/Unit/Mail/HtmlToTextTest.php
index 02c6e11d08783179f420235f19446382d73a371d..34e1478a8be8291fce61a696068b60ca949a127a 100644
--- a/core/modules/system/tests/src/Unit/Mail/HtmlToTextTest.php
+++ b/core/modules/system/tests/src/Unit/Mail/HtmlToTextTest.php
@@ -74,7 +74,13 @@ protected function assertHtmlToText(string $html, string $text, string $message,
   public function testTags(): void {
     global $base_path, $base_url;
     $tests = [
-      // @todo Trailing linefeeds should be trimmed.
+      // Tests tag inside <a>.
+      '<a href = "https://www.drupal.org"><b>Drupal.org</b> our site</a>' => "*Drupal.org* our site [1]\n\n[1] https://www.drupal.org\n",
+      // Tests newlines are stripped from anchor text.
+      '<a href = "https://www.drupal.org">Drupal' . "\n.org</a>" => "Drupal.org [1]\n\n[1] https://www.drupal.org\n",
+      // Tests newlines and carriage returns are stripped from anchor text.
+      '<a href = "https://www.drupal.org">Drupal' . "\r\n.org</a>" => "Drupal.org [1]\n\n[1] https://www.drupal.org\n",
+      // @todo Trailing newlines should be trimmed.
       '<a href = "https://www.drupal.org">Drupal.org</a>' => "Drupal.org [1]\n\n[1] https://www.drupal.org\n",
       // @todo Footer URLs should be absolute.
       "<a href = \"$base_path\">Homepage</a>" => "Homepage [1]\n\n[1] $base_url/\n",