wp_mail function not working in user query loop

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.