Jump to content

Recommended Posts

I have a website with a form that i want the data to be emailed to me when they submit, I have got this done but the slight issue is that when someone views the web page it believes they have submitted and then emails me a blank email and i dont know what is wrong please can someone help

	      <form>
				<p><label for="name">Name:</label><br />
				<input type="text" name="name" id="name" value="" />
		</p>
	<p>Message Type</p>
				<p><select name="type">
<option value="webprob">Website Problem</option>
<option value="sugguest">Suguestion</option>
<option value="feedback">Feedback</option>

</select>
    </p>
		<p><label for="message">Message:</label><br />

				<textarea cols="60" rows="11" name="message" id="message"></textarea><br /></p>
		<p><input type="submit" class="formbutton"/>          
            <p>
              <?php
// Receiving variables
@$name = addslashes($_GET['name']);
@$type = addslashes($_GET['type']);
@$message = addslashes($_GET['message']);

// Validation
if (strlen($name) <0)
{
die("<p align='center'><font face='Arial' size='3' color='#000000'>Please complete all the required fields</font></p>");
}
if (strlen($name) >20)
{
die("<p align='center'><font face='Arial' size='3' color='#000000'>Please complete all the required fields</font></p>");
}

//Sending Email to form owner
$pfw_header = "From: $name\n"
  . "Reply-To: $name\n";
$pfw_subject = "Website Feedback";
$pfw_email_to = "My email address";
$pfw_message = "name: $name\n"
. "type: $type\n"
. "message: $message\n"
@mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;
echo("<p align='center'><font face='Arial' size='3' color='#000000'>Your form has been submitted and will be evaluated soon.</font></p>");
?>
          </form></p>

 

Many thanks

 

Nathan

Link to comment
https://forums.phpfreaks.com/topic/183996-php-mailing-system-slight-issue/
Share on other sites

you want to check if your get variables are set before you do the mail stuff, so What i would do is add a name to your submit button

<input type="submit" name="submit" class="formbutton"/>

 

and then do something like

if (isset($_GET['submit'])){
//do email stuff
}
else {
//whatever you want to do if the form wasn't submit
}

 

another thing, the reason your validation currently isn't working is because you have a logical error

if (strlen($name) <0)

that will only trigger the error if the length of the string is in the negatives (because it has to be less than 0) you probably want something like

if (strlen($name) <= 0)
//or
if (strlen($name) < 1)

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.