Hey man!
I just made a "Contact Us" page myself just a couple of days ago. Currently I am having trouble with getting the error messages to print out, but I think i have the general idea of how to tackle this.
I do this with PHP and different attributes that i can pull up with PHP to check what has happend.
First I have this in contact.php
Code:
<?PHP
if(isset($_REQUEST['mailsent'])){
$value = $_REQUEST['mailsent'];
if($value == "true"){
$message = "<h3>Your E-Mail has now been sent</h3>";
}
}
if(isset($_REQIEST['mailsent']) && isset($_REQUEST['reason'])){
$reason = $_REQUEST['reason'];
$value = $_REQUEST['mailsent'];
echo $reason . ', ' . $value . 'Works?';
if($value == "false" && $reason == "1"){
$message = "<h3>No E-Mail added.</h3>";
}elseif($value == "false" && $reason == "2"){
$message = "<h3>Bad E-Mail : Incorrect structure.</h3>";
}elseif($value == "false" && $reason == "3"){
$message = "<h3>Bad E-Mail : Incorrect domain.</h3>";
}else{
$message = "<h3>Invalid value returned from server. #423</h3>";
}
}
if(!isset($_REQIEST['mailsent'])) {
$contactmsg = "<h5>Contact Process</h5>
<p>
At the moment this page is locked for public. If you want to become a member at this page you will need to e-mail us an application.
This should consist of some information about yourself, what knowledge you possess and in which fields as well as why you want to become a member.
</p><p>
Please free to read through our EULA and ToS for further information on what we might be able to offer you.
The information you send us will be treated as private and not passed along to anyone else.
</p><p>
Have a nice day!
</p>";
echo $contactmsg;
}
if(isset($message)){ echo $message; }
?>
<form action="send.php" method="post">
<div class="req"><label for="nameinput">Name:</label>*</div>
<input type="text" tabindex="1" id="nameinput" name="nameinput" class="textinput" /><br />
<div class="req"><label for="emailinput">E-Mail:</label>*</div>
<input type="text" tabindex="2" id="emailinput" name="emailinput" class="textinput" /><br />
<div class="req"><label for="subjectinput">Subject:</label>*</div>
<input type="text" tabindex="3" id="subjectinput" name="subjectinput" class="textinput" /><br />
<br />
<div class="req"><label for="messageinput">Message:</label>*</div>
<textarea id="messageinput" tabindex="4" name="messageinput" class="textarea"></textarea><br />
<br />
<input type="submit" id="submit" name="submit" tabindex="5" value="Submit" class="buttonSubmit" />
<div id="stylesheetTest"></div>
</form>
The form at the bottom send the info from the form to send.php
Code:
<?PHP
//////////////////////////////////////
// Code to send E-Mail through form //
//////////////////////////////////////
// Include correct files
include('includes/functions.php');
include('includes/globals.php');
if(isset($_POST['submit'])){
// Assign variables to forms
$to = "info@waah.eu";
$from = $_POST['emailinput'];
$name = $_POST['nameinput'];
$subject = "Hallux :: " . $_POST['subjectinput'];
$message = $_POST['messageinput'];
$headers = "From: $name <$from>";
// Check if the e-mail is correct.
$verify = verify($from);
if($verify == -1){
header ("Location: " . $mailsent . "&mailsent=false&reason=1");
}elseif($verify == -2){
header ("Location: " . $mailsent . "&mailsent=false&reason=2");
}elseif($verify == -3){
header ("Location: " . $mailsent . "&mailsent=false&reason=3");
}elseif($verify == -0){
mail($to,$subject,$message,$headers);
header ("Location: " . $mailsent . "&mailsent=true");
}
}else{
echo 'Not sent correctly';
}
?>
the verify() function checks if the field "E-Mail" is correctly filled in and if not returns a error value from -1 to -3 and 0 if the E-Mail is valid.
Here is the verify()-function
Code:
<?PHP
function verify($email){
// If no e-mail address is inputted to begin with the user will get an error message.
if(!isset($email)){
// Return incorrect e-mail to main site.
return -1;
}
// Check so the e-mail uses allowed chars and correct structure.
// If match not made it sends user back to form.
if (!preg_match('/^[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+(?:\.[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+)*\@[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+(?:\.[^\x00-\x20()<>@,;:\\".[\]\x7f-\xff]+)+$/i', $email)){
// Return incorrect e-mail to main site.
return -2;
}
// Grab the domain from the e-mail adress.
$domain = strstr($email, '@');
$domain = substr($domain, 1); // Shifts selection by one so not @ is added with the domain.
// Checks that the domain is resolved to an IP.
// If hostname isn't resolved to and IP user is sent back to form.
if (!ip2long(gethostbyname($domain))){
// Return incorrect e-mail to main site.
return -3;
}
// It passed all the tests, hurrah for us!
return 0;
}
?>
Depending on what value is returned it later echoes the message in contact.php... this should work, atm it doesn't, but I think i will find the error soon enough
Hope this helps you!
__________________
“It is better to create than to be learned, creating is the true essence of life”
- Barthold Georg Niebuhr
Please login or register to view this content. Registration is FREE
|