I created a function which I use to send an email when a specific button is pressed. This works great, except that it always ends up in spam instead of the inbox.
This is the function:
function search_notify_email() {
// Set variables
$email = $_POST['email'];
$title = $_POST['title'];
$content = $_POST['content'];
$location = $_POST['location'];
$siteurl = $_POST['siteurl'];
$networkurl = network_site_url();
$themeurl = get_stylesheet_directory_uri();
// Call Change Email to HTML function
add_filter( 'wp_mail_content_type', 'set_email_html_content_type' );
$to = $email;
$subject = "Attention: Test!";
$message = "<html>
<body>
Testing
</body>
</html>";
$headers[] = 'From: Example <[email protected]>';
if ( wp_mail($to, $subject, $message, $headers) ) {
// Success
} else {
// Error
}
die();
// Remove filter HTML content type
remove_filter( 'wp_mail_content_type', 'set_email_html_content_type' );
}
add_action('wp_ajax_nopriv_search_notify_email', 'search_notify_email');
add_action('wp_ajax_search_notify_email', 'search_notify_email');
I have other emails sent on my site with the same email address used and these do not end up in the spam folder.
Any idea why this happens?