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.
UPDATE:
Code updated based on first answer, but still no results.
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.
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 <videkivendeghazak@gmail.com>'
);
$to = $user->user_email;
$subject = "Fiókod hamarosan törlésre kerül";
$body = "<p style='font-size: 16px; margin-bottom: 20px;'>Kedves Szállásadó!</p><p style='font-size:14px; margin-bottom: 20px;'>A <a href='https://videkivendeghazak.hu'>Vidéki Vendégházak oldalon</a> felhasználói fiókod 30 nap múlva <b>automatikus törlésre kerül minden általad létrehozottt tartalommal együtt.</b></p><p style='font-size:14px; margin-bottom: 20px;'>Amennyiben nem szeretnéd, hogy fiókod törlésre kerüljön, úgy a következő 30 napon belül lépj be felhasználói fiókodba <a href='https://videkivendeghazak.hu/fiokom'>ezen a linken keresztül.</a></p><p style='font-size:14px;'>Üdvözlettel: a Vidéki Vendégházak csapata</p>";
wp_mail( $to, $subject, $body, $headers );
}
}
}
I also tried to delete the filter lines (if/else) and set $to to my email manually, neither worked, the mail is not going out.