Jump to content

Need "Contact Us" email script


indie

Recommended Posts

I would like a pretty simple email contact form to put on my website. I would like it to show the IP of the sender if possible, and make sure they use a valid email. Fields should be name, username (but not required), and comment.

 

I would like the ability to just paste the code into a website page, and I can style it myself.

 

Thanks

Link to comment
Share on other sites

Here's a very crude, simple version of a contact form, no special fancy looks or anything added.. But some of the security concerns are dealt with.. All you have to do is take a look through and add your email, your subject etc where required its only a couple variables..

 

Other than that you need to have the attached file to this post, enjoy! Hope it helps.

 

I whipped this up pretty quick from scratch minus the one little email validation class, but had that laying around as I use it in a lot of builds I do. So I may have missed a ; or a quotation mark somewhere in the code doing it as quick as I did, I didn't test it but know as long as theres no missing things to break the code like I mentioned it should work without fail copy and paste. Oh and upload of that one file to the same directory.

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<?php
include_once('email.validator.php');
function getRealIpAddr(){if(!empty($_SERVER['HTTP_CLIENT_IP'])){$ip=$_SERVER['HTTP_CLIENT_IP'];}elseif(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];}else{$ip=$_SERVER['REMOTE_ADDR'];}return $ip;}
function cleaner4inputs($theInput){$theOutput = stripslashes($theInput);$theOutput = htmlspecialchars($theOutput, ENT_QUOTES);$theOutput = str_replace("'", "\\'", $theInput); return $theOutput; /*$theOutput = htmlentities($theOutput);*/}
$messageDisplay = "";
if((isset($_POST['submitme'])) AND ($_POST['submitme'] == "Submit")){
if(empty($_POST['name']){$errorFound = "yes"; $messageDisplay .= "• Did not provide a Name, whats your name?";}else{$myname = cleaner4inputs($_POST['name']);}
if(empty($_POST['uname']){$myuname = "Not Provided";}else{$myuname = cleaner4inputs($_POST['uname']);}

if(empty($_GET['email'])){$errorFound = "yes"; $messageDisplay .= "• Email was not provided.<br />";}else{
	$em=$_GET['email'];
    	$validator = new EmailAddressValidator;
    	if ($validator->check_email_address($em)){
			/*email is in a good format*/
		$myemail = $em;
	}else{
		$errorFound = "yes"; $messageDisplay .= "• Email not formated correctly. Example of good: myemail@example.com<br />";
	}
}
if(empty($_POST['comment']){$errorFound = "yes"; $messageDisplay .= "• Did not provide a comment, what did you want to say?";}else{$mycomment = cleaner4inputs($_POST['comment']);}

if($errorFound == "yes"){echo $messageDisplay;}else{
echo "Thank you for sending us a message, we will get back to you soon";
$myipa = getRealIpAddr();
$email_who = 'your email address';
$titlesubject = "your subject tag?";
$message = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <title>' . $titlesubject . '</title>
</head>
</head>
<body>
<strong>Name:</strong> '.$myname.'
<strong>Username:</strong> '.$myuname.'
<strong>Email Address:</strong> '.$myemail.'
<strong>Comment:</strong> '.$mycomment.'
<strong>Users IP:</strong> '.$myipa.'
</body>
</html>';
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'Content-type: text/html; charset=us-ascii' . "\r\n";
$headers .= 'From: noreply@monkeytooth.net' . "\r\n";
$headers .= 'Reply-To: noreply@monkeytooth.net' . "\r\n";
$headers .= '1\r\nX-MSMail-Priority: High' . "\r\n";
$headers .= 'X-Mailer: Monkey Tooth Mailer' . "\r\n";
//$headers .= 'To: ' . $to . ' <' . $to2 . '>' . "\r\n";
mail($email_who, $titlesubject, $message, $headers);

}

}else{/*do nothing assumes form just loaded*/}
?>
<body>
<form action="$_SERVER['PHP_SELF']" method="post">
<strong>Name:</strong> <input type="text" name="name" id="name" value="" /><br />
<strong>Userame:</strong> <input type="text" name="uname" id="uname" value="" /><br />
<strong>Email:</strong> <input type="text" name="email" id="email" value="" /><br />
<strong>Comment:</strong><br /><textarea name="comment" id="comment"></textarea><br />
<input type="submit" name="submitme" id="submitme" value="Submit" />
</form>

</body>
</html>

 

[attachment deleted by admin]

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.