Skip to content

Conversation

brholstein
Copy link

Fixes #210

The diff is quite large but when you filter out the whitespace changes it is quite simple:

diff --git a/includes/wp-mail-api.php b/includes/wp-mail-api.php
index 2d910a1..4cf1487 100644
--- a/includes/wp-mail-api.php
+++ b/includes/wp-mail-api.php
@@ -495,8 +495,11 @@ function wp_mail( $to, $subject, $message, $headers = '', $attachments = array()
         }

         // Email Fallback
+        if (!$isFallbackNeeded) return true;
+
         $isFallbackEnabled = get_option('email_fallback') ?: 'no';
-        if ($isFallbackNeeded && $isFallbackEnabled === 'yes') {
+        if (!($isFallbackEnabled === 'yes')) return false;
+
         global $phpmailer;

         // (Re)create it, if it's gone missing.
@@ -735,9 +738,6 @@ function wp_mail( $to, $subject, $message, $headers = '', $attachments = array()
             return false;
         }
     }
-
-        return true;
-    }
 }

The if ($isFallbackNeeded && $isFallbackEnabled === 'yes') { check is not exhaustive of all the possibilities so when a fallback is needed, but not enabled it falls through to the default return value of true at the bottom of the function which is incorrect. To address this I've:

  1. Added a guard statement to exit early with true it no fallback is needed.
  2. Added a guard statement to exit early with false if a fallback is needed but disabled.

I've also removed the fall through return true at the end of the function as it is now unreachable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Failed attempts to send emails are reporting as succeeded when the fallback method is disabled

1 participant