Jump to content

Need help making the script for my contact form.


SebbieHE

Recommended Posts

<form action="#" id="ContactForm">

<div class="success"> Contact form submitted! I will be in touch soon.</div>

<fieldset class="left">

<div class="block">

<label class="name padRight3">

<span class="title1">Name:</span>

<span class="bg"><input type="text" value="" class="input"></span>

<span class="error">*This is not a valid name.</span> <span class="empty">*This field is required.</span> </label>

<label class="email">

<span class="title1">Email:</span>

<span class="bg"><input type="email" value="" class="input"></span>

<span class="error">*This is not a valid email address.</span> <span class="empty">*This field is required.</span></label>

 

<label class="phone">

<span class="title1">Phone:</span>

<span class="bg"><input type="tel" value="" class="input"></span>

<span class="error">*This is not a valid number.</span> <span class="empty">*This field is required.</span> </label>

</div>

 

<div class="block">

<label class="message">

<span class="title1">Message:</span>

<span class="bg"><textarea rows="1" cols="2"></textarea></span>

<span class="error">*The message is too short.</span> <span class="empty">*This field is required.</span> </label>

</div>

<div class="formButtons">

<div class="formBtn">

<a href="#" data-type="submit" class="moreButton">Send</a>

</div>

<div class="formBtn">

<a href="#" data-type="reset" class="moreButton">Clear</a>

</div>

</div>

</fieldset>

</form>

Okay sorry for late reply, lost the php so had to make it again. Will this php work with the HTML?

 

 

<?php

if(isset($_POST['email'])) {

 

$email_to = "[email protected]";

$email_subject = "Query";

 

 

function died($error) {

 

echo "We are very sorry, but there were error(s) found with the form you submitted. ";

echo "These errors appear below.<br /><br />";

echo $error."<br /><br />";

echo "Please go back and fix these errors.<br /><br />";

die();

}

 

 

if(!isset($_POST['name']) ||

!isset($_POST['email']) ||

!isset($_POST['phone']) ||

!isset($_POST['message'])) {

died('We are sorry, but there appears to be a problem with the form you submitted.');

}

 

$first_name = $_POST['name']; // required

$last_name = $_POST['email']; // required

$email_from = $_POST['phone']; // required

$comments = $_POST['message']; // required

 

$error_message = "";

$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';

if(!preg_match($email_exp,$email_from)) {

$error_message .= 'The Email Address you entered does not appear to be valid.<br />';

}

$string_exp = "/^[A-Za-z .'-]+$/";

if(!preg_match($string_exp,$first_name)) {

$error_message .= 'The First Name you entered does not appear to be valid.<br />';

}

if(!preg_match($string_exp,$last_name)) {

$error_message .= 'The Last Name you entered does not appear to be valid.<br />';

}

if(strlen($comments) < 2) {

$error_message .= 'The Comments you entered do not appear to be valid.<br />';

}

if(strlen($error_message) > 0) {

died($error_message);

}

$email_message = "Form details below.\n\n";

 

function clean_string($string) {

$bad = array("content-type","bcc:","to:","cc:","href");

return str_replace($bad,"",$string);

}

 

$email_message .= "Name: ".clean_string($name)."\n";

$email_message .= "Email: ".clean_string($email)."\n";

$email_message .= "Phone: ".clean_string($phone)."\n";

$email_message .= "Message: ".clean_string($message)."\n";

 

 

 

$headers = 'From: '.$email_from."\r\n".

'Reply-To: '.$email_from."\r\n" .

'X-Mailer: PHP/' . phpversion();

@mail($email_to, $email_subject, $email_message, $headers);

?>

 

 

 

Thank you for contacting us. We will be in touch with you very soon.

 

<?php

}

?>

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.