• Resolved zewtastic

    (@zewtastic)


    I have built some custom front-end pages for WP and generally have been able to use all plugins with little trouble in my custom php code.

    But when I tried to call wp_mail() I get this error: PHP Fatal error: Call to undefined function wp_mail().

    As I use a SMTP plugin is it possible this is hurting things?

    Is there a basic reason I am not picking up the wp_mail function in my front end code when I can see and use all the other WP functions?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter zewtastic

    (@zewtastic)

    I absolutely call this:

    require_once( ABSPATH . ‘wp-includes/pluggable.php’ );

    which includes the function:

    function wp_mail( $to, $subject, $message, $headers = ”, $attachments = array() ) {
    // Compact the input, apply the filters, and extract them back out

    No idea why it is throwing an error.

    I have an SMTP plugin, but wp_mail fails with it active and disabled.

    Sounds like you calling wp_mail before it is defined.

    Make sure you are not calling it, or any other pluggable function, until at least the plugins_loaded hook.

    Thread Starter zewtastic

    (@zewtastic)

    My index loads these in this sequence, and I am able to use other plugins functions without trouble.

    define(‘WP_USE_THEMES’, false);
    require ‘wp-blog-header.php’;
    require ‘pluggable.php’;

    Is this correct or missing something?

    Thread Starter zewtastic

    (@zewtastic)

    The interesting thing is the smtp plugin configuration page works fine, sends a test email. And registration emails are sent fine.

    But trying to call the function in front-end page results in that error. And I have no trouble with any other functions, wp or plugin.

    Very confused.

    Thread Starter zewtastic

    (@zewtastic)

    OK found my issue. I’m an idiot.

    I was trying to call the wp_mail() function from a page I loaded via a jquery call.

    A page called in that way does not inherit functions loaded from the main index.php.

    Thanks for the help.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Trouble getting wp_mail() to work’ is closed to new replies.