wp_mail function ends up in spam?

Question

I created a wp_mail function which I use to send an email when a specific button is pressed. This works great, except that it will always end up in the 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 <noreply@example.com>';

    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 adress used and these will not end up in the spam folder.

Any idea why this happens?

0
, jockebq 3 years 2019-03-25T09:23:15-05:00 0 Answers 73 views 0

Leave an answer

Browse
Browse