Hi Guys,
I posted a few days ago sort of about this and that helped me learn a few things. My attempt at code was a complete fail but I now have this new .php file. I have edited to work with my contact form (name, email and comments). It appears to show errors correctly however when everything is done correct and the thank you screen comes up there is NO email sent I have a feeling this is not due to the php more to do with the email settings? Here is my code what do I need to set up?
<?php
if(isset($_POST['email'])) {
$email_to = "myemail@mydomain.co.uk";
$email_subject = "Email Subject";
function getIpAddr()
{
if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet
{
$ip=$_SERVER['HTTP_CLIENT_IP'];
}
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy
{
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
$ip=$_SERVER['REMOTE_ADDR'];
}
return $ip;
}
function died($error) {
// your error code can go here
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();
}
// validation expected data exists
if(!isset($_POST['name']) ||
!isset($_POST['email']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_POST['name']; // required
$email_from = $_POST['email']; // required
$comments = $_POST['comments']; // required
$error_message = "";
$email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$";
if(!eregi($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "^[a-z .'-]+$";
if(!eregi($string_exp,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "General Email Request From Pedal Car.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_message .= "Customer.......: ".clean_string($first_name)."\n\n";
$email_message .= "E-Mail.........: ".clean_string($email_from)."\n\n";
$email_message .= "Comments.......: ".clean_string($comments)."\n\n";
$email_message .= "Vistor IP......: ".getIpAddr()."\n\n";
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- include your own success html here -->
<!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>
<!-- For Menu Column -->
<link href="styleSheet.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="ContactFormThankyou">
<div align="center">Thankyou for your enquiry, we will be in touch as soon as possible. </div>
</div>
</body>
</html>
<?php
}
?>
Cheers, Dan