Form sending blank emails

I am getting an email from my contact form at the same time every night, but I dont think it is spam since the only thing in my email is:

Results from contact form:

And that is all that is in my email. Also if I submit the form without filling out any fields I will get the name of the field like “Name:” with no information following it so I dont think it is the result from users.
:confused:
When I implement a spry validation to the input fields I still get the blank emails at the same time.

My site is still in the testing phase and I am wanting to launch it to its actually domain soon so any help would be nice.

Oh and I am obviously new to PHP.

PHP script that sends emails rip away, lol:

<?php

// Subject of email sent to you.
$subject = ‘Results from Contact Form’;

// Your email address. This is where the form information will be sent.
$emailadd = ‘myemail@yahoo.com’;

// Where to redirect after form is processed.
$url = ‘http://www.mydomain.com’;

$req = ‘0’;

$text = "Results from Testimonial form:

“;
$space = ’ ';
$line = ’
';
foreach ($_POST as $key => $value)
{
if ($req == ‘1’)
{
if ($value == ‘’)
{echo “$key is empty”;die;}
}
$j = strlen($key);
if ($j >= 20)
{echo “Name of form element $key cannot be longer than 20 characters”;die;}
$j = 20 - $j;
for ($i = 1; $i <= $j; $i++)
{$space .= ’ ‘;}
$value = str_replace(’
', “$line”, $value);
$conc = “{$key}:$space{$value}$line”;
$text .= $conc;
$space = ’ ‘;
}
mail($emailadd, $subject, $text, ‘From: ‘.$emailadd.’’);
echo ‘<META HTTP-EQUIV=Refresh CONTENT="0; URL=’.$url.’”>';

?>

Thanks for the help. I am not sure if I fully understand what you are saying but I did plug in your above code so hopefully I can figure it out and get it to work.

I have never messed with php and I am trying to find someone I know to help me with this part but I am not having any luck so I appreciate the tips. I though this would be real easy and I could find a working code, but it has created a small inconvenience at the moment.

here is what I did:


<?php

// Subject of email sent to you.
$subject = 'Results from Index Form';

// Your email address. This is where the form information will be sent.
$emailadd = 'coryfaust21@yahoo.com';

// Where to redirect after form is processed.
$url = 'http://www.lubbockalamoremodeling.com';

// Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty.
$req = '1';

// --------------------------Do not edit below this line--------------------------
$text = "Results from Index form:\
\
";
$space = ' ';
$line = '';
foreach ($_POST as $key => $value)
{
if ($req == '1')
{
 mail($emailadd, $subject, $text, 'From: '.$emailadd.'');

    echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
if ($value == '')
{echo "$key is empty";die;}
  
}
$j = strlen($key);
if ($j >= 20)
{echo "Name of form element $key cannot be longer than 20 characters";die;}
$j = 20 - $j;
for ($i = 1; $i <= $j; $i++)
{$space .= ' ';}
$value = str_replace('\
', "$line", $value);
$conc = "{$key}:$space{$value}$line";
$text .= $conc;
$space = ' ';
}
mail($emailadd, $subject, $text, 'From: '.$emailadd.'');
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';

?>

sorry i still have my debug marks on indexresults.php code

just after

$line = '';

please remove


print_r($_POST);
echo '<br />';

and before


mail($emailadd, $subject, $text, 'From: '.$emailadd.'');

please remove

exit;

thank you for posting more informations, sorry to confused you, i didn’t meant it that way. please try this one out,

this is your form


<form id="form2" action="test.php" method="post">
	<h3><span>Free Estimate</span></h3>   
	<label for="text1">Full Name:</label>
	<span id="sprytextfield1">
	<input type="text" name="Name" id="text1" size="30" />
	<span class="textfieldRequiredMsg">A value is required.</span></span>
	<label>Phone Number:</label>
	<span id="sprytextfield2">
	<input type="text" name="Phone" id="text2" size="30" />
	<span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span>
	<label>Email:</label>
	<input name="email" type="text" size="30"/>             
	<label for="textarea1">Message:</label>
	<span id="sprytextarea1">
	<textarea name="Message" id="textarea1" cols="30" rows="4"></textarea>
	<span class="textareaRequiredMsg">A value is required.</span><span class="textareaMinCharsMsg">Minimum number of characters not met.</span></span>
	<input type="hidden" name="token" value="1" /> 
	<input name="submit" type="submit" value="Submit" class="subbttn" />
</form>

this is your indexresults.php file


if($_POST['token']){
// Subject of email sent to you.
$subject = 'Results from Index Form';

// Your email address. This is where the form information will be sent.
$emailadd = 'YOUR_EMAIL@yahoo.com';

// Where to redirect after form is processed.
$url = 'http://www.lubbockalamoremodeling.com';

// Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty.
$req = '1';

// --------------------------Do not edit below this line--------------------------
$text = "Results from Index form:\
\
";
$space = ' ';
$line = '';

print_r($_POST);
echo '<br />';
foreach ($_POST as $key => $value){
	if ($value == ''){
		echo "$key is empty";
		die;
	}

	$j = strlen($key);
	if ($j >= 20){
		echo "Name of form element $key cannot be longer than 20 characters";
		die;
	}

	$j = 20 - $j;

	for ($i = 1; $i <= $j; $i++){
		$space .= ' ';
	}

	$value = str_replace('\
', "$line", $value);
	$conc = "{$key}:$space{$value}$line";
	$text .= $conc;
	$space = ' ';
}
exit();
mail($emailadd, $subject, $text, 'From: '.$emailadd.'');
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
}

The problem there is your indexresults.php file doesn’t make any initial checking before proceeding with the whole script processing so it sends out a blank email every time it is accessed. I just added a “token” as a sign that it was triggered from your html form.

There are some things that you still need to do with it, take a look for example on this thread http://www.sitepoint.com/forums/showthread.php?t=693340

never trust user input. you can use filter input just like what is discussed on the link i posted above.


$name = filter_input(INPUT_POST, 'name', FILTER_SANITIZE_STRIPPED);
$email = filter_input(INPUT_POST, 'email', FILTER_SANITIZE_EMAIL);

you can study it and if there’s a problem, go back here, a lot of people are willing to help

I don’t know where do you intend to flag $req to proceed with the email sending but upon reading all available information’s on this topic, this should prevent it from sending you blank email.


if ($req == '1'){
	mail($emailadd, $subject, $text, 'From: '.$emailadd.'');
	echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
}

you might also consider filtering user inputs before you process them

I appreciate your help and I will definitely check back in if I need anymore help or tips. Thanks again.

fire this action on the form submit and check that the required filled are not blank…

Rajub: I have never used php until now so I found the php script in a tutorial so I am not sure why it has the met refresh or what it even does?

I plan on adding anti spamming when I am completely done with the site and its ready to be launched, but at the moment I am occupied with other aspects of the site unless you believe it will fix the problem, but I am thinking it is something with my code since the emails are blank.

thanks for the reply too.


<form id="form2" action="indexresults.php" method="post">
        <h3><span>Free Estimate</span></h3>   
        <label for="text1">Full Name:</label>
        <span id="sprytextfield1">
        <input type="text" name="Name" id="text1" size="30" />
        <span class="textfieldRequiredMsg">A value is required.</span></span>
        <label>Phone Number:</label>
        <span id="sprytextfield2">
        <input type="text" name="Phone" id="text2" size="30" />
        <span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span>
        <label>Email:</label>
        <input name="email" type="text" size="30"/>             
        <label for="textarea1">Message:</label>
        <span id="sprytextarea1">
        <textarea name="Message" id="textarea1" cols="30" rows="4"></textarea>
        <span class="textareaRequiredMsg">A value is required.</span><span class="textareaMinCharsMsg">Minimum number of characters not met.</span></span>
        <input name="submit" type="submit" value="Submit" class="subbttn" />
		</form> 

When I fire the submit action the form will not process since the required fields are blank and when I make it have no required fields and fire the submit action the emails still show the label names with empty information next them.

Show us the form first. You should have a captcha field or something to prevent spams. Why are you using META refresh ?