Jump to content

PhP mailing system - Slight issue


blink359

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)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.