1

I'm new to PHP and HTML working on a website both codes seem to be working. I'm trying to edit an existing contact us form and send the form to a default email but it is getting to the spam folder.

Here is my HTML code part:

    <div class="row-fluid">
      <div class="span8" id="divMain">

        <h1>Contact Us</h1>
        <h3 style="color:#;"></h3>
        <hr>
        <!--Start Contact form -->                                                      
        <form name="enq" action="contact-form-handler.php" method="POST" onsubmit="return validation();">
          <fieldset>
            <input type="text" name="name" id="name" value=""  class="input-block-level" placeholder="Name" maxlength="80" />
            <input type="text" name="email" id="email" value="" class="input-block-level" placeholder="Email" maxlength="80" />
            <textarea rows="11" name="message" id="message" class="input-block-level" placeholder="Message" maxlength="1024"></textarea>        
            <div class="actions">
              <input type="submit" value="&nbsp;&nbsp;Send&nbsp;&nbsp;" name="submit" id="submitButton" class="btn btn-inverse pull-left" title="Click here to submit your message!" />
            </div>
          </fieldset>
        </form>                  
        <!--End Contact form -->                                             
      </div>

and here is my PHP code:

<?php
$name=$_POSt['name'];
$vistor_email=$_POST['email'];
$message=$_POST['message'];

$email_from='ex2@gmail.com';
$email_subject="New request to A-Akawi";
//$email_body="User Name:$name.\n"."User Email:$vistor_email.\n"."User message:$message.\n";

$body = <<<EMAIL
You have received a new request from $name with the following email address $vistor_email.
The following request is:
$message.


EMAIL;

$to ='ex1@gmail.com';
$headers .= "From: Johnson Smith <noreply@ksar.com> . \r\n" ;
$headers .='Reply-To: '. $to . "\r\n" ;
$headers .= "Organization: Sender Organization\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= "X-Priority: 3\r\n";
$headers .= "X-Mailer: PHP". phpversion() ."\r\n";

mail($to,$email_subject,$body,$headers);
header("location: contact.html");
?>

I'm getting it to the spam even after adding the headers how to fix it?

S K
  • 41
  • 5
  • 1
    [PHP mail function doesn't complete sending of e-mail](https://stackoverflow.com/questions/24644436/php-mail-function-doesnt-complete-sending-of-e-mail) – Definitely not Rafal Mar 24 '21 at 14:31
  • I was getting the emails into the spam folder tried a bunch of methods but still not receiving any into the mail box, only the spam. – S K Mar 24 '21 at 15:33
  • In which folder the E-Mail is being put into depends on your provider. If (lets say) google decides that your servers activity is suspicious, then there is nothing you (as a programmer) can do. But if you (as a client/user) say that all E-Mails coming from yourserver.com are not spam, then your mails wont get there. You might want to message all major E-Mail provider and ask them if they were willing to not put your mails into the spam folder. But thats a route most people do not do until they reach a high status, such as for example facebook. – Definitely not Rafal Mar 25 '21 at 07:09
  • My advice: try to make your mails look as little suspicious as you can. Meaning if your server is myserver.com. Then all your mails you sent out from must end with `@myserver.com`. – Definitely not Rafal Mar 25 '21 at 07:12

1 Answers1

0

As far as I know you also need to add the Return-Path: to the header of your e-mail. But there could be many more reasons why your email is going to the spam. The spf records in your DNS could be configurate wrong or the IP of your server is listed in spam filters

Baracuda078
  • 677
  • 1
  • 5
  • 10