Error in my plugin with wp_mail function ()

I’m developing my first plugin in WordPress. Then one of the functions need to send an email.

But when I call the function wp_mail () throws me this error:

Read More

Fatal error: Call to undefined function wp_mail ()

How should I define this function in my plugin??

Thanks!

Related posts

Leave a Reply

3 comments

  1. Just include wp-load.php and go ahead!

    require('../../../wp-load.php');
    

    or

    require('wp-load.php');
    

    Depending how your script are loaded.

  2. The wp_mail() function is not available until after the action plugins_loaded, so if you try to use it before that point it will throw an error because the function is undefined at that point.

    So rather than simply calling wp_mail(), you should be hooking that process to an action so that it occurs after the function has been loaded.

    A lot of plugins use init as the action hook to connect their action to. init comes after plugins_loaded, so if you use that, it should work.