# I'm getting blank emails using php contact forms

**URL:** <https://forum.kirupa.com/t/im-getting-blank-emails-using-php-contact-forms/294774>\
**Category:** programming\
**Created:** [August 19, 2009, 5:55pm UTC](https://forum.kirupa.com/t/im-getting-blank-emails-using-php-contact-forms/294774 "2009-08-19T17:55:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ksuguy25](https://avatars.discourse-cdn.com/v4/letter/k/fbc32d/32.png) [@Ksuguy25](https://forum.kirupa.com/u/Ksuguy25)\
**Post date:** [August 19, 2009, 5:55pm UTC](https://forum.kirupa.com/t/im-getting-blank-emails-using-php-contact-forms/294774/1 "2009-08-19T17:55:25Z")

</div>

Hey guys,

Got bit of a dilemma. I’ve created a form in php for my website,  
somehow i’m getting blank emails every 2 or 3 weeks. The form works  
great when people enter data but at times, I just receive nothing. I  
tested the form on different computers to confirm it works. Here is  
what I have done on the html contact form. I’ve used the built in  
javascript dreamweaver cs4 validation for the fields and used captcha  
for a layer of security (it saved as contact.php). Now here is the php  
code.

```php

<?php
               $errors = array();
         
         if(empty($_POST['name'])){
            $errors[] = 'Please enter your name';
            
         } else {
            
            echo "";
         }
         
         
         if(empty($_POST['email'])){
            $errors[] = 'Please enter your email';
            
         } else {
            
            echo "";
            
         }
         
         if(empty($_POST['comments'])){
            $errors[] = 'Please enter your comments';
            
         } else {
            echo "";
         }
            
            
            $emailPattern = '/^[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}$/i';
   
           $to = "fake@email.com";
   
   
         $subject = 'whaaaat?';
         $from = 'whoever';
         
      
         
         
         $name = safe (stripslashes( $_POST['name']) );
         $email = safe($_POST['email'] );
         $phone = safe($_POST['phone'] );
         $reasons = safe ($_POST['reasons']);
         $search = safe( $_POST['search']);
         $facebook = safe($_POST['facebook'] );
         $wsb = safe ( $_POST['wsb']);
         $other = safe( $_POST['other']);
         $comments = safe(stripslashes($_POST['comments']) );
         
         
         $headers = "From: ". $from . "<" . $to. ">
";  
         $headers .= "Reply-To: " . $email . "
"; 
         $headers .= "Return-path: ". $email;
         

           $message .= "Name: " . $name . "
";
         $message .= "Email: " . $email . "

";
         $message .= "Phone Number: " . $number . "

";
         $message .= "Reasons: " . $reasons . "

";
         $message .= "Facebook: " . $facebook . "

";;
         $message .= "WSB-TV: " . $wsb . "

";
         $message .= "Other: " . $other . "

";
         $message .= "Comments: " . $comments . "

";
         
         if (mail($to,$subject,$message,$headers)){ 
         
        echo "Thank you so much for your Inquiry. I'm looking forward in serving you soon!"; 
      } else { 
        echo "&Result=error"; 
      } 
   
   function safe($string) 
   { 
      $pattern = "/\r|
|\%0a|\%0d|Content\-Type:|bcc:|to:|cc:/i"; 
      return preg_replace($pattern, '', $string); 
   }

        ?>

```

Please help and thanks in advanced!
