Hi all. I need help with one HTML form. I taked a web sie template and formed it to suit my need but at the end the form build in it was not working. I have add php file and action to use the php file from what i have seen in internet but there is still something wrong. Can someone help me, what is missing?

HTML code:

<article id="content"><div class="ic"></div>
                <div class="wrapper">
                    <h2>Форма за контакт</h2>
                    <form name="htmlform" method="post" id="ContactForm" action="html_form_send.php">
                        <div>
                            <div  class="wrapper">
                                <span>Име:*</span>
                                <div class="bg"><input class="input" type="text" name="first_name" id="first_name"></div>
                            </div>
                            <div  class="wrapper">
                                <span>Адрес:*</span>
                                <div class="bg"><input class="input" type="text" name="client_address" id="client_address"></div>                              
                            </div>
                            <div  class="wrapper">
                                <span>E-mail:*</span>
                                <div class="bg"><input class="input" type="text" name="client_email" id="client_email"></div>                              
                            </div>
                            <div  class="textarea_box">
                                <span>Коментар:*</span>
                                <div class="bg"><textarea class="input" name="comments" id="comments" cols="1" rows="1"></textarea></div>                               
                            </div>
                            <a href="#" class="button1" onClick="document.getElementById('ContactForm').submit()">Изпрати</a>
                            <a href="#" class="button1" onClick="document.getElementById('ContactForm').reset()">Изчисти</a>
                        </div>
                    </form>
                </div>
            </article>

PHP code:

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

    $email_to = "*****@********.eu";

    $email_subject = "website html form submissions";

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

    $first_name = $_POST['first_name']; // required
    $last_name = $_POST['client_address']; // required
    $email_from = $_POST['client_email']; // required
    $comments = $_POST['comments']; // required

    $error_message = "";
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
  if(!preg_match($email_exp,$client_email)) {
    $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(strlen($textarea) < 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 .= "First Name: ".clean_string($first_name)."\n";
    $email_message .= "Last Name: ".clean_string($client_address)."\n";
    $email_message .= "Email: ".clean_string($email_from)."\n";
    $email_message .= "Comments: ".clean_string($comments)."\n";

$headers .= 'Content-type: text/plain; charset=UTF-8' . "\r\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); 
?>

<!-- place your own success html below -->

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

<?php
}
die();
?>

when i press send in the web site it brings me to empty page ********/html_form_send.php

I suggest you use some echo's so you can see where the code stops.

Error found.
1) In the php code there was some variable name mix :)
2) In front of the mail operator was @ (not sure if that is a mistake)

So it works now?

The @ hides warnings generated by the function call. Although sometimes useful, you don't see it if something is not working.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.