Jump to content

Recommended Posts

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

$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 = 'huuh';

$from = 'whaat?';

 

 

 

 

$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. ">\r\n"; 

$headers .= "Reply-To: " . $email . "\r\n";

$headers .= "Return-path: ". $email;

 

 

  $message .= "Name:  " . $name . "\n";

$message .= "Email: " . $email . "\n\n";

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

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

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

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

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

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

 

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|\n|\%0a|\%0d|Content\-Type:|bcc:|to:|cc:/i";

return preg_replace($pattern, '', $string);

}

 

  ?>

 

Please help and thanks in advanced!

Do you realize even though you have some error checking for name, email and comments that you do absolutely nothing different if there are errors? If someone submits the form with nothing entered you will get a blank email. You should not rely on JavaScript for validation since people can have it turned off. It's a nice user feature, but it should be used as an add-on to server-side validation.

 

By the way, your blocks of code to validate have an else that echo's an empty string. Why?

 

Try something like this:

 

<?php
     function safe($string) 
     { 
         $pattern = "/ | |%0a|%0d|Content-Type:|bcc:|to:|cc:/i"; 
         return preg_replace($pattern, '', $string); 
     }

     $errors = array();

     if(empty($_POST['name'])){
        $errors[] = 'Please enter your name';
     }         

     if(empty($_POST['email'])){
        $errors[] = 'Please enter your email';
     }

     if(empty($_POST['comments'])){
        $errors[] = 'Please enter your comments';
     }

     if (count($errors)>0)
     {
         //Only a very basic error handler
         //You could alternatively send user back to the form
         echo "The follwing errors occured:<br> ";
         foreach ($errors as $error)
         {
             echo " - $error<br> ";
         }
     }
     else
     {
  
         $emailPattern = '/^[^@s]+@([-a-z0-9]+.)+[a-z]{2,}$/i';
   
         $to = "service@rodriguezstudios.com";
         //$to ="atlnycdude23@gmail.com";  // ----> Use this $to email declation just in case in a emergency.

         $subject = 'Sales Inquiries, Potential/ReturningCustomer Related Questions';
         $from = 'Rodriguez Studios';

         $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"; 
         } 
     }

        ?>

Most def i'll have them re-direct so they can enter their info again. the reason why i have the echo part empty, if I return them if the info is correct then the returned value of (i.g) name, phone,comments will come like this. jane doe84993333heyhoware you. So i prefer the thanks for submitting output. One more thing. When the user submits the form to me, the validation and the captcha prevents the form to return any data to me. I'm just receiving blank emails, period. But much appreciated for your assistance guys!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.