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

    Remove the @ before mail; It will give you some errors which can then be used to determine the problem.

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

      Well thank you for the quick reply. I promptly opened dreamweaver and changed the file, Uploaded it and filled in my form...

      The result was: "Thank you for your enquiry" haha so no errors 🙁

      I am guessing thats not meant to happen :/

        hm.. I do not see anything clearly wrong (But not very experienced in mail functions; wrote one once, and never looked back 😉

        • Could be your mail is being marked as spam by your spam filter
        • Mail is not sent.

        In your case, I would do something like:

            if (mail($email_to, $email_subject, $email_message, $headers) )
            {
            $message = "Thankyou for your enquiry, we will be in touch as soon as possible. ";
            }
          else 
            {
            $message = "Wow..! We are sorry; Our server did not understand that. please try again. ";
            }
        
        
        // in the HTMl you echo out $message
        

          I just stuck that in and the check worked apart from it still comes back ok with "Thank you for your enquiry"...

          Is the problem with my email settings? E.g mail forwarding or something? I am new to hosting a website. I set up the email through my domain, are there any settings which allow the website to send mail?

            THat means the email was handled ok, a.f.a.i.k. Where are you sending the mail to? Have you checked there in the spam filter?

            I am at the end of my knowledge when it comes to mail, I must admit. My preferred hosting provider has so far taken care of all server-settings for mail.

              The email account is brand new and only has 1 message which was a test from my email. (spam checked) :p There must be some settings somewhere. I'll leave this open and see if some mail guru comes along 🙂 Thanks a lot for the help though, at least I know its not my code _ haha

                On a side note... I previously has a fancy Rollover Image as the submit button but that doesn't work, does the contact form have to have a official Form Button? :p

                  Who's your web host? I have a couple different providers and one requires smtp authentication as their mail servers are separate servers altogether.. which means I can't use the php mail function.

                  In the simplest form, you should be able to add this to a php page all by itelf:

                  <?php
                  mail('youremail@gmail.com', 'My subject', 'the message', null,'-finfo@yourdomain.info');
                  ?>

                  Replace 'youremail' and 'yourdomain' with your info... then simply visit that page and it will send an email. If not.. I'd be checking with my host.

                    Thanks for all the help...

                    I contacted my web host (uk2) and they simply changed one setting and it works 🙂 sometimes annoying problems have the simplest solutions!

                      SoapDodger;10986031 wrote:

                      Thanks for all the help...

                      I contacted my web host (uk2) and they simply changed one setting and it works 🙂 sometimes annoying problems have the simplest solutions!

                      Lol,
                      I gave you the right solutionn after all, when I said that my provider usually handles the server-side 😃

                        Write a Reply...