diff --git a/src/wp-includes/class-phpmailer.php b/src/wp-includes/class-phpmailer.php
index 7f5e353578..d7abcb4b46 100644
--- a/src/wp-includes/class-phpmailer.php
+++ b/src/wp-includes/class-phpmailer.php
@@ -2690,7 +2690,7 @@ protected function encodeFile($path, $encoding = 'base64')
             if (!is_readable($path)) {
                 throw new phpmailerException($this->lang('file_open') . $path, self::STOP_CONTINUE);
             }
-            $magic_quotes = get_magic_quotes_runtime();
+            $magic_quotes = PHP_VERSION_ID < 70400 && get_magic_quotes_runtime();
             if ($magic_quotes) {
                 if (version_compare(PHP_VERSION, '5.3.0', '<')) {
                     set_magic_quotes_runtime(false);
