0

I'm new in plugin development. I would like to use this simple function in Wordpress to send mail to users. I saw this code in the documentation everything is simple and straight forward but this code returns false. Why ?

require_once explode( 'wp-content', __FILE__ )[0] . 'wp-load.php';
function send_mail() {
    $to      = 't.testmail@gmail.com';
    $subject = 'The subject';
    $body    = 'The email body content';
    $headers = array( 'Content-Type: text/html; charset=UTF-8' );

    $send_message = wp_mail( $to, $subject, $body, $headers );

    if ( $send_message ) {
        echo 'Email was sent';
    } else {
        echo 'Email sending was aborted';
    }
}

send_mail();

1 Answers1

0

According to the documentation (https://developer.wordpress.org/reference/functions/wp_mail/) the mail could not be sent. Reasons could be many. Have you checked the debug log of WordPress (https://wordpress.org/support/article/debugging-in-wordpress/)?

HFranz
  • 33
  • 3