Contactform PHP/AJAX

Dear PHPers,

Recently i made a HTML5/CSS3/PHP/AJAX website. I’ve made an contact form which is located in one of the html files (contact.html)

[code]

                                    <form id="contact_form" name="contact_form" method="post" action="page-contact-ajax.php">
                                        <div class="row">
                                            <div class="six columns b0">
                                                <div class="form-row field_text">
                                                    <label for="contact_name">Your Name </label><em>(required)</em><br>
                                                    <input id="contact_name" class="input_text required" type="text" value="" name ="contact_name">
                                                </div>
                                                <div class="form-row field_text">
                                                    <label for="contact_phone">Your Phone Number </label><em>(optional)</em><br>
                                                    <input id="contact_phone" class="input_text" type="text" value="" name ="contact_phone">
                                                </div>
                                            </div>
                                            <div class="six columns b0">
                                                <div class="form-row field_text">
                                                    <label for="contact_email">Your E-Mail Address </label><em>(required)</em><br>
                                                    <input id="contact_email" class="input_text required" type="text" value="" name ="contact_email">
                                                </div>
                                                <div class="form-row field_text">
                                                    <label for="contact_subject">Subject </label><em>(required)</em><br>
                                                    <input id="contact_subject" class="input_text required" type="text" value="" name ="contact_subject">
                                                </div>
                                            </div>
                                            <div class="clear"></div>
                                        </div>
                                        <div class="form-row field_textarea">
                                            <label for="contact_message">Message: </label><br>
                                            <textarea id="contact_message" class="input_textarea required" type="text" value="" name ="contact_message"></textarea>
                                        </div>
                                        <div class="form-row field_submit">
                                            <input type="submit" value="Submit Now" id="contact_submit" class="btn">
                                            <span class="loading hide"><img src="assets/images/loader.gif"></span>
                                        </div>
                                        <div class="form-row notice_bar">
                                            <p class="notice notice_ok hide">Bedankt voor uw bericht. We nemen zsm contact met u op.</p>
                                            <p class="notice notice_error hide">Er is een fout ontstaan. Probeer het later nogmaals.</p>
                                        </div>
                                    </form> <!-- END #contact_form -->[/code]

And here is the contact.php file:

[php]<?php

// *** PERSONAL SETTINGS

// The email address for receiving messages sent via the contact form
$recipient_email = "[email protected]";

// The name of your website
$website_name = “NedLumo”;

// The subject of the messages received
$subject = “[” . $website_name . “] Message sent via the contact form”;

// ***

if (isset($_POST[“name”]) && empty($_POST[“username”])) { // “username” - is a hidden field to prevent bot spam

// *** Calculate the message sending time (local time)
if (isset($_POST["timezone_offset"])) {
	$timezone_offset = $_POST["timezone_offset"]; // time difference between UTC time and sender local time, in minutes
} else {
	$timezone_offset = 0;
}
$local_unixtime = mktime(date("H"), date("i")-$timezone_offset, date("s")-date("Z"), date("m") , date("d"), date("Y"));
$tz_offset_in_hours = round($timezone_offset/60);
$utc = $timezone_offset > 0 ? -$tz_offset_in_hours : "+".abs($tz_offset_in_hours);
$local_date = date("m/d/Y H:i:s", $local_unixtime) . " (UTC" .$utc. ")"; // for example: UTC+2, UTC+0, UTC-7
// ***

$sender_name = $_POST["name"]; // sender name
$sender_email = $_POST["email"]; // sender email
$msg_subject = $_POST["subject"]; // subject of message
$msg_text = $_POST["message"]; // message text

$content = $local_date . "\n\n";
if ($sender_name) $content .= "Name: " . $sender_name . "\n";
if ($sender_email) $content .= "Email: " . $sender_email . "\n";
if ($msg_subject) $content .= "Subject: " . $msg_subject . "\n";
if ($msg_text) $content .= "\n" . $msg_text;

$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/plain; charset=UTF-8\r\n";
$headers .= "From: " . $sender_email . "\r\n";
$headers .= "Reply-To: " . $sender_email . "\r\n";
$headers .= "X-Mailer: PHP/" . phpversion();

// send email message
if (mail($recipient_email, $subject, $content, $headers)) echo 'success';
else echo 'error';

} else {

die('Direct access to this page is not allowed.');

}

?>[/php]

My problem here is the following:
When i fill in the fields on the contact page (online) and when i want to sent it, i get all fields highlighted red (error or something) its like the script thinks that i havent filled in any fields.

Can you please help me? Whats wrong in the script/html page?

My best regards,
luck7

Sorry ladz wrong PHP code

Here is the right one:

[php]<?php

// Site Info
$site_name = ‘Work Fast’;
$site_email = ‘[email protected]’;

if(isset($_POST[‘contact_email’])){

$contact_name    = $_POST['contact_name'];
$contact_phone   = $_POST['contact_phone'];
$contact_email   = $_POST['contact_email'];
$contact_subject = $_POST['contact_subject'];
$contact_message = $_POST['contact_message'];

$contact_name         = "Name: $contact_name <br />";
$contact_email        = "Email:  $contact_email <br />";
$contact_phone         = "Phone Number: $contact_phone <br />";
$contact_subject       = "Subject: $contact_subject <br />";
$contact_message       = "Message: $contact_message <br />";

$to = $site_email;
$subject = "You have a new email from ".$site_name;
$header  = 'MIME-Version: 1.0' . "\r\n";
$header .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$header .= 'From:'.$contact_email. " \r\n";
$message = "
	You have a new message! <br />
	$contact_name;
	$contact_email;
	$contact_phone;
	$contact_subject;
	$contact_message;
";

// Send Mail
if(mail($to,$subject,$message,$header)) {
	$send = true;
} else {
	$send = false;
}

if(isset($_POST['ajax'])){
	if($send)
		echo 'success';
	else
		echo 'error';
}

}

?>[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service