awesomemotive / WP-Mail-SMTP

The most popular WordPress SMTP and PHP Mailer plugin. Trusted by over 3 million sites.
https://wordpress.org/plugins/wp-mail-smtp/
GNU General Public License v3.0
55 stars 34 forks source link

Not working on REST API funtion #119

Closed Tsjippy closed 2 years ago

Tsjippy commented 2 years ago

Expected Behavior

Mails should always be send by smtp mail

Current Behavior

Smtp mail works only on the normal webpages, not in REST API functions.

If I go to the page with shortcode “test” I receive an e-mail from the correct e-mail adress If I go to the rest api page i.e. https://SOMETHING.org/wp-json/sim/v1/sendtestemail I get the e-mail from wordpress@SOMETHING.org

See this code:


add_shortcode("test",function ($atts){
    global $Modules;

    echo sendTestEmail();

    return 'e-mail send';
});

function sendTestEmail(){
    wp_mail('MYEMAIL@gmail.com' , 'test e-mail', 'test');

    return 'E-mail send';
}

add_action( 'rest_api_init', function () {
    // add element to form
    register_rest_route(
        'sim/v1/',
        '/sendtestemail',
        array(
            'methods'               => 'GET',
            'callback'              =>  __NAMESPACE__.'\sendTestEmail',
            'permission_callback'   => '__return_true',
        )
    );
});

Possible Solution

Steps to Reproduce

See above. Use the code given

alexander-sakal commented 2 years ago

Hey @Tsjippy. I've tested your code and it works well. I was not able to replicate the issue with the REST API.

Maybe it's a plugin conflict. Can you verify that you don't have other mailing/SMTP plugins activated? Also, can you provide more details like the WP version, PHP version, and active plugins (with versions), please?

Tsjippy commented 2 years ago

I finally figured what was wrong: removing the '/' from 'sim/v1/' fixed the problem