PHP / JS help please..

5 replies
Morning All,

This is driving me mad but I'm pretty sure someone who knows what they are doing will spot the mistake easily. I can handle HTML and CSS but JS & PHP elude me..

I have downloaded a template CSS website which has a contact form on it that I cannot get working..

The contact page is here - Fencing Essex

Then I found out I needed a PHP page to handle the request to get it to email to me. So I downloaded and adjusted this -

<?php
if(isset($_POST['email'])) {

// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "sales@collinsonfencing.com";
$email_subject = "Your email subject line";


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['author']) ||
!isset($_POST['email']) ||
!isset($_POST['text'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}

$author = $_POST['author']; // required
$email_from = $_POST['email']; // required
$text = $_POST['text']; // 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,$author)) {
$error_message .= 'The Name you entered does not appear to be valid.<br />';
}
if(strlen($text) < 2) {
$error_message .= 'The Message 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($author)."\n";
$email_message .= "Email: ".clean_string($email)."\n";
$email_message .= "Comments: ".clean_string($text)."\n";


// create email headers
$headers = 'From: '.$email."\r\n".
'Reply-To: '.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
?>

<!-- include your own success html here -->

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

<?php
}
?>

If I go onto it and send a message I get the success html page but no email appears in my inbox....

Any ideas please??

Cheers

Steve
#php
  • HI ya..
    I have tested the same code and was able to receive the email without any issue.Dont think there should be any issue with the code.
    Can you please check if your SMTP settings are correct
    If the email address is correct.
    Also check the spam folder if the email is getting there.

    Hope this helps
    {{ DiscussionBoard.errors[7921313].message }}
    • Profile picture of the author Steve2129
      Originally Posted by eluminoustechnologies View Post

      Also check the spam folder if the email is getting there.
      So to reiterate - I can master HTML and CSS but still do not know how to check the spam folder - DOH...

      Thank you soo much - that was doing my head in. Just checked the spam and there are the test emails I was sending!!!

      Cheers

      Steve
      {{ DiscussionBoard.errors[7921504].message }}
      • Profile picture of the author Steve2129
        Ok,

        Just found a problem with it - I get the email now and it tells me the name and the message but not the senders email address....any idea please?

        Steve
        {{ DiscussionBoard.errors[7921517].message }}
        • Profile picture of the author Steve2129
          I found it - the email_from part should be just email....
          {{ DiscussionBoard.errors[7921639].message }}
        • Profile picture of the author viescripts
          Originally Posted by Steve2129 View Post

          Ok,

          Just found a problem with it - I get the email now and it tells me the name and the message but not the senders email address....any idea please?

          Steve
          you also pass the customer email address in the email headers.
          When you click reply, isn't the email there?
          {{ DiscussionBoard.errors[7921642].message }}

Trending Topics