I'm trying to send an e-mail to every user who is logged in more than a year ago (based on woocommerce meta value from database), but the e-mails do not go out. In my code I'm trying to filter myself for the testing phase, so that only me get the mail, after testing these lines would be deleted (marked in code). We are using SMPT with mailing queue and we are using wp_mail function in other similar codes, where wp_mail working correct.

Query seems fine on site fronted testing, cause I got my email address in $to variable with echo.

Tried to add "ini_set("display_errors",1); error_reporting(E_ALL);" to code but got no errors.

Also tried to delete the filter lines (if/else) and set $to to my email manually, neither worked, the mail is not going out.

function my_notifyOldUsers() {

global $wpdb;

$query = $wpdb->prepare("SELECT user_id FROM $wpdb->usermeta WHERE ( meta_key='wc_last_active' AND DATE_ADD(FROM_UNIXTIME(meta_value), INTERVAL 1 DAY) > NOW() )");  //will be 365 DAY and "<" after testing

$oldusers = $wpdb->get_results($query, ARRAY_N);
require_once( ABSPATH.'wp-admin/includes/user.php' );

    foreach ($oldusers as $olduser) {
        $user = get_userdata( $olduser[0] );
        $user_azonosito = $user->ID;        //this line will be deleted after testing
        if( $user_azonosito == 4210 ) {     //this line will be deleted after testing, ID 4210 is myself

            $headers = array(
                'Content-Type: text/html; charset=UTF-8',
                'From: Vidéki Vendégházak <sensitive data removed>'
            $to = $user->user_email;
            $subject = "TESZT";
            $body = "<p style='font-size: 16px; margin-bottom: 20px;'>TESZT</p>";

            wp_mail( $to, $subject, $body, $headers );
  • if you're relying on your hosts email sending to do this then there is a very high chance your emails are going out but being discarded by anti-spam measures. Most people use a dedicated service or SMTP details for an account at a reliable email service
    – Tom J Nowell
    Dec 3, 2022 at 17:51

1 Answer 1


It's possible that there's an issue with your SMTP configuration or with the mailing queue. You can try using a debugging plugin, such as WP Mail Logging, to help diagnose the issue. This plugin logs all emails sent through WordPress and displays them in the admin dashboard, allowing you to see if the emails are being sent and any errors that may be occurring.

Alternatively, you can try using a different email sending method, such as the WordPress email function wp_mail_from_home(), to see if that fixes the issue. This function bypasses the default email sending methods in WordPress and sends emails directly from your website's server.

It's also possible that there's a problem with the email addresses you're trying to send to. You can try using a different email address to test if the emails are being sent properly.

Lastly, make sure that the code you posted above is being executed properly. You may want to add some debug statements, such as error_log(), to ensure that the code is running and the correct values are being passed to the wp_mail() function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.