0

I have set up a contact form which is to send email to anyone from WordPress page. It's sending email but all are going to SPAM folder. How to prevent it to go to Spam folder but go to Inbox?

however, I gave it try from another wordpress site, all emails going to inbox perfectly, and I've found a difference that is all email going to inbox has one extra line in details that is-

mailed-by: p6plcpnl0235.prod.phx3.secureserver.net

But the emails going to the SPAM folder doesn't have this above line, Is it can be a cause? If so how to enable this secureserver.net

Can anyone please help me?

Here is what I am using in page-

      <?php
        //if "email" variable is filled out, send email
         if (isset($_REQUEST['email']))  {

        //Email information
        $admin_email = "admin@mail.com";
        $email = $_REQUEST['email'];
        $subject = $_REQUEST['subject'];
        $comment = $_REQUEST['comment'];


        //send email
        mail($email, $subject, $comment, "From:" .$admin_email);

        //Email response
        header('Location: /email-sent');
      }

      //if "email" variable is not filled out, display the form
      else  {
?>


    <div class="container send-email-form-wrapper"> 
      <div class="row"> 
       <div class="send-email-form">
        <form method="post">

          <li> Email: <input name="email" type="text" /> </li>
          <li>  Subject: <input name="subject" type="text" /></li>
          <li> Message: <textarea name="comment" rows="5"></textarea></li>
          <li><input type="submit" value="Submit" /></li>
        </form>

      </div>
   </div>

</div> 
  <?php
    }
?>
munna_695
  • 61
  • 7
  • You might want to use `wp_mail()` instead of `mail()`. And then configure a proper SMTP server with authentication: https://gist.github.com/butlerblog/c5c5eae5ace5bdaefb5d. Also, your header `'Location: /email-sent'` looks uncommon, to me at least. – Hans Sep 22 '18 at 17:36
  • Hi Michael, you mean to write the line like this- wp_mail($email, $subject, $comment, "From:" .$admin_email); By the way looks like this - https://gist.github.com/butlerblog/c5c5eae5ace5bdaefb5d first part need to use in config.php And for the second part "wp_mail_smtp.php" do I create a new file for it in same root of config.php Actually, I am not fully expert in PHP so some more explanations may help :) Also, 'Location: /email-sent' redirect sender to the confirmation page after submission and it's working properly. – munna_695 Sep 22 '18 at 17:59
  • Check the documentation of wp_mail() for further infos. They put the SMTP details in wp-config.php for security reasons. The function from wp_mail_smtp.php you can then add to your theme's function.php or your plugin file. I read that some servers put emails in spam when the headers are not valid. – Hans Sep 22 '18 at 22:31

1 Answers1

0

This is more about your hosters internal sendmail mail setup that is used by the mail() function. If possible, try to use an tested SMTP mailer like Swiftmailer or PHPMailer instead. That way you could work around the sendmail smarthost configuration issue.

mblaettermann
  • 1,916
  • 2
  • 17
  • 23
  • Hi @mblaettermann could you give me a specific source link that I can use. I am not fully expert in PHP, so some more explanation might help. By the way, looks like this above is working with Godaddy hosting but I am facing the problem with a site hosted in 1&1.com – munna_695 Sep 22 '18 at 17:49