0

This is my first post. Yeah!

I got a problem with my contact form. it sends the email to my spambox.

How to avoid the spambox using php mail() function?

I already search on stackoverflow and serverfault but i can't seem to find the right solution....

This is the code that i am using.

<?php
if (isset($_POST['email'])
&& isset($_POST['name'])
&& isset($_POST['message'])
) {

$admin_email = "info@mywebsite.nl";
$name = htmlspecialchars($_POST['name']);
$phone = htmlspecialchars($_POST['phone']);
$email = htmlspecialchars($_POST['email']);
$subject = "Contact";
$comment = nl2br(htmlspecialchars($_POST['message']));
$to = $admin_email;

$headers = "From: " . $email . "\r\n";
$headers .= "Reply-To: " . $email . "\r\n";
$headers .= "Return-Path: The Sender <" . $admin_email . ">\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";

$message .= "<html>
<body style='margin: 0; padding: 0; font-family: Roboto Slab;'>
<table cellpadding='0' cellspacing='0' width='100%'>
<tr>
 <td>
 <table style='border: 1px solid #c7c5c5;' align='center' cellpadding='0'         cellspacing='0' width='600' style='border-collapse: collapse;'>
   <tr height='301'>
     <td align='center' bgcolor='#ffffff' style='padding: 0 0 0 0;'>
      <img src='myimage' alt='Contact' width='100%' height='100%' style='display: block;' />
     </td>
   </tr>
   <tr>
     <td bgcolor='#eee' style='padding: 40px 30px 40px 30px; background-color: #eee;'>
       <table cellpadding='0' cellspacing='0' width='100%'>
        <tr>
         <td>
            <h1 style='font-family: Roboto Slab;'>Contactinformation</h1>
         </td>
        </tr>
        <tr>
         <td style='padding: 20px 0 30px 0; font-family: Roboto Slab;'>
         <b>From:</b> " . $naam . " <br/>
         <b>E-mail:</b> " . $email . " <br/>
         <b>Phone:</b> " . $phone . "
         </td>
        </tr>
        <tr>
         <td>
            <h1 style='font-family: Roboto Slab;'>Message</h1>
         </td>
        </tr>
           <tr>
               <td style='padding: 20px 0 30px 0; font-family: Roboto Slab;'>
                " . $comment . "
               </td>
           </tr>
       </table>
     </td>
   </tr>
   <tr>
     <td bgcolor='#33333' style='padding: 30px 30px 30px 30px; background-color: #333;'>
       <table  cellpadding='0' cellspacing='0' width='100%'>
         <td style='color: #fed136; font-family: Roboto Slab;' width='70%'>
             Copyright &reg;
             <a style='color: #fed136; font-family: Roboto Slab;' href=''></a> " . $thisyear . "<br/>
         </td>
         <td align='right'>
          <table border='0' cellpadding='0' cellspacing='0'>
           <tr>
            <td>
             <a style='color: #fed136; font-family: Roboto Slab;' href=''>

             </a>
            </td>
           </tr>
          </table>
         </td>
       </table>
     </td>
   </tr>
 </table>
   </td>
    </tr>
    </table>
       </body>
        </html>";
      mail($to, $subject, $message, $headers);
     }
     ?>

Many thanks in advance!

Dave
  • 290
  • 2
  • 12

1 Answers1

0

Some mail clients like gmail has certain rules to mark a mail as spam. If the mail subject or body contains
free/promo/offer/,etc. and it is not from a trusted sender, it will be marked as spam. Also such mail clients blacklist some senders and list it in spam box. It happen to many big companies too.

Sagar V
  • 12,158
  • 7
  • 41
  • 68