In your email code you’re using mail
PHP function, whereas WordPress uses its own internal wp_mail
function that then sends the email using PhpMailer (for many different reasons) .. which should be using PHP’s mail
fn but there’s a number of different things that could be causing problems.
You can also install the “WP Mail Logging” plugin to log any outgoing emails from your server, to see if WordPress is actually sending the email, and maybe your hosting provider is preventing the from being sent, adding them to some kind of queue, or even discarding them (to eliminate WordPress from the problem).
I recommend installing the log plugin above as you mentioned you’re receiving emails but the end user is not. Their email provider could be sending your emails to SPAM or JUNK folders — so use the mail logging plugin to confirm the emails are actually being sent from your server.
As others mentioned in comments, you should also check your hosting providers error logs. If you don’t know where to find those, you also enable WP_DEBUG_LOG
in your wp-config.php
file to write to a debug.log
file that will be located at /wp-content/debug.log
by setting the following values in the wp-config.php file:
define( 'WP_DEBUG', true );
define( 'WP_DEBUG_LOG', true );
More information can be found at the link below, or by contacting your hosting company: https://codex.wordpress.org/WP_DEBUG
Another thing to mention — make sure on your hosting provider that you correctly setup SPF and DKIM to help with email deliverability