Jump to content

please, help with contact form


afallingpanda

Recommended Posts

hello guys, today i have a problem i cant seem to solve ;/

 

so basically i got a page with a contact form, once the form has been submited, it sends (action="sent.php") to page "sent.php", this page has the php script i made to actually send the email. now my problem is, once someones clicks send, and gets redirected to sent.php, the email gets sent ( as intended) but then when the user is on that page all they have to do is just refresh the page and it keeps sending the email. now of course as you can imagine this can be a problem. how do i work my way around this guys?

here is my code for contactus.php:

print"<table cellspacing=0 cellpadding=0 border=0 class=\"contacttable\">";
print"<form method=\"post\" action=\"sent.php\">";

print"	<tr>";
print"		<td class=\"contactlabel\"><label for=\"fname\">* First Name</label></td>";
print"		<td class=\"contactlabel\"><label for=\"lname\">* Last Name<label></td>";
print"	</tr>";

print"	<tr>";
print"		<td><input class=\"contactbox\" type=\"text\"  id=\"fname\" name=\"fname\" maxlength=\"30\" required></td>";
print"		<td><input class=\"contactbox\" type=\"text\" id=\"lname\" name=\"lname\" maxlength=\"30\" required></td>";
print"	</tr>";

print"	<tr>";
print"		<td class=\"contactlabel\"><label for=\"email\">* Email</label></td>";
print"		<td class=\"contactlabel\"><label for=\"groupname\">Company/Group Name<label></td>";
print"	</tr>";

print"	<tr>";
print"		<td><input class=\"contactbox\" type=\"text\"  id=\"email\" name=\"email\" maxlength=\"50\" required></td>";
print"		<td><input class=\"contactbox\" type=\"text\" id=\"groupname\" name=\"groupname\" maxlength=\"50\"></td>";
print"	</tr>";

print"	<tr>";
print"		<td class=\"contactlabel\"><label for=\"subject\">* Subject</label></td>";
print"		<td class=\"contactlabel\"><label for=\"reference\">Reference<label></td>";
print"	</tr>";

print"	<tr>";
print"		<td><input class=\"contactbox\" type=\"text\"  id=\"subject\" name=\"subject\" maxlength=\"100\" required></td>";
print"		<td><input class=\"contactbox\" type=\"text\" id=\"reference\" name=\"reference\" maxlength=\"50\"></td>";
print"	</tr>";

print"	<tr>";
print"		<td colspan=\"2\" class=\"contactlabel\"><label for=\"message\">* Message:</label></td>";
print"	</tr>";

print"	<tr>";
print"		<td colspan=\"2\"><textarea class=\"textarecontact\" name=\"message\" id=\"message\" maxlength=\"2000\" required></textarea></td>";
print"	</tr>";

print"	<tr>";
print"		<td colspan=\"2\"><input class=\"submitbutton\" type=\"submit\" value=\"Send An Email\"></td>";
print"	</tr>";

print"</table>";
print"</form>";

and here is my code for sent.php:

<?php
include("../inc/header.php");
// php for contact form


	// here we put in an if statement to check against missing variables (empty values)
		if (isset($_POST['fname']) && isset($_POST['lname']) && isset($_POST['email']) && isset($_POST['subject']) && isset($_POST['message'])){
			
			$fname=$_POST['fname'];
			$lname=$_POST['lname'];
			$groupname=$_POST['groupname'];
			$reference=$_POST['reference'];
			$email=$_POST['email'];
			$subject=$_POST['subject'];
			$message=$_POST['message'];

			// here we are checking to see if that value anything and not just black.

			if (!empty($fname) && !empty($lname) && !empty($email) && !empty($subject) && !empty($message) ){
				
				// this is doing a check for max length, its doing it in php just in case the user
				// cheats and bypasses the html check.
			if (strlen($fname>30) || strlen($lname>30) || strlen($groupname>50) || strlen($email>50) || strlen($subject>100) || strlen($reference>100) || strlen($message>2000)){
				echo"sorry, that max length for a field has been exceeded.";
			}

			$to='support@eclipse-developers.com';
			$emailsubject=$subject;
			$body=$fname." ".$lname."\nCompany Name: ".$groupname."\nRef: ".$reference."\nMessage: ".$message;
			$headers= 'From: '.$email;

			// mails, if statement so if its true (mail did send)
				if	(mail($to,$emailsubject,$body,$headers)){

					echo'Thanks for contacting us.';					

				}else{

					echo'Sorry, an error occurred. Try again later.';

				}
			}
			
			} else{
			
			
			
			}
			


?>

thanks guys

Link to comment
Share on other sites

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.