• Resolved Daniel P.

    (@danidub)


    Hello, I’m trying to use wp_mail function and have some feedback in hostings that have PHP mail() function disabled.

    If that’s the case when trying to execute wp_mail function, you’ll get a PHP:

    Fatal error: Uncaught Error: Call to undefined function PHPMailer\PHPMailer\mail()

    Is there a way to check, have some exception returned or some feedback when this function is not present?

    Would be nice for any user using the wp_mail function to have an error message or simply detect it and show some feedback instead a PHP fatal error…

Viewing 1 replies (of 1 total)
  • Thread Starter Daniel P.

    (@danidub)

    For anyone trying to catch this error and not breaking your code you can use:

    try {
        $sent = wp_mail( $to, $subject, $body, $headers );
    } catch (Error $e) {
        if ( str_contains($e->getMessage(), 'Call to undefined function PHPMailer\PHPMailer\mail()') ){
            echo "Problem with PHP mail() function (not found)";
        }
    }
    
Viewing 1 replies (of 1 total)
  • The topic ‘wp_mail function failing with PHP fatal error, no feedback or exception’ is closed to new replies.