• When I try to send email using wp_mail in php file I get following message:

    See screenshot
    I have configured WP Mail SMTP for gmail and when I send test mail it works, but when I send wp_mail email I get that error.

    I use simple php script just to test is it working:

    <php
    $to=”[email protected]”;
    $subject=”Test”;
    $body=”This is test mail”;
    wp_mail( $to, $subject, $body, $headers );
    ?>

    • This topic was modified 7 years, 4 months ago by guber90.
    • This topic was modified 7 years, 4 months ago by guber90.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Generally speaking, WordPress uses the send mail feature of the web server itself to send transactional email (password resets, system notifications, etc.).

    Are you trying to build a plugin that hooks in to the send mail feature?

    Here’s more: https://developer.ww.wp.xz.cn/reference/functions/wp_mail/

    Thread Starter guber90

    (@guber90)

    I am just trying to send mail using wp_mail, simple mail like that one i posted

    <php
    $to=”[email protected]”;
    $subject=”Test”;
    $body=”This is test mail”;
    wp_mail( $to, $subject, $body, $headers );
    ?>

    And it doesnt work, have no idea why.

    Dion

    (@diondesigns)

    If that’s the entire script you’re using for testing, then the problem is that you’re calling wp_mail() without first loading WordPress. Make sure your test script is in the WordPress root directory, which is where the wp-load.php file and /wp-includes directory are located. Then add the following line to the top of your test script:

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

    This will load WordPress and allow you to use the wp_mail() function.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘wp_mail not working’ is closed to new replies.