Hello together,

this code of contact form works - but i dont like the alert, so i decided to modify the code, that it should write into a div "thank you..". The problem is, it doesnt work? It think the issue is because the echo doesnt know where to write in...Maybe you can help me - THX

/// HTML ///

<section id="main-content">

    <div class="text-intro"><h2>CONTACT</h2></div>
    <div id="thanks"></div>
    <div class="columns features">
            <br />
          <form action="contact.php" method="post" id="contact-form" class="contact-form">
            <textarea id='message' maxlength='10000' name='message' placeholder='Hello...'></textarea>
            <div class='crayonico'></div>
            <input class='text-input' id='senderEmail' maxlength='50' name='email' placeholder='E-Mail' type='email'>
            <div class='emailico'></div>
            <input class='btn btn-input' id='sendMessage' name='sendMessage' type='submit' value='SEND'>
          </form>
            <br /><br /><br /><br /><br />


    </div>

/// PHP ///

<?php
$field_email = $_POST['email'];
$field_message = $_POST['message'];

$mail_to = 'email@email.de  ';
$subject = 'Message from a site visitor '.$field_name;

$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;

$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";

$mail_status = mail($mail_to, $subject, $body_message, $headers);

if ($mail_status){ 
  echo "Thanks for your mail...";
}else{
  echo "Please correct your data.";
}  
?>

Furthermore, is it possible to only allow sending the message by validation? The issue is that i can send it without an email adress...Thank you so much!

In your HTML I can't see you actually echoing the mail_status?

hai klaragold
please clarify the following things little bit more

1. where do you want to display the status message?(what i mean is you want to display with in the contact.php page or you want to display that in seperate page)

is it possible to only allow sending the message by validation? The issue is that i can send it without an email adress..

2. what do you mean by validation in the above statement? (i mean you wnat to check whether it is valid mail address or not or something than that)

please explain it clearly so that we are ready to help you

Hello Radhakrishna.p,

  1. On my contact.html there is the <form> with the different fields. If i press the send button the php file should be started. No problem. But for feedback there should be a div above the contact form with text, that is generated by the php script with thank you or something...

  2. The validation works, but if i dont write something into the email field the script doesnt recognize it but the send button works and i get an email without the customers mail adress :/

Hope i explained it clearly :)

Thanks

hai klaragold

you may better to use ajax concept in javascript/jquery for this requirement

why because you are in contact.html page you need to send the details of this page to contact.php

if you want to use jquery following URL heps you a lot how to use jquery ajax

http://phpcodeforbeginner.blogspot.in/2013/01/jquery-ajax-tutorial-and-example-of.html

and then display status information as follows (in the above example he displays the outout by using)

$("#msg").html("some message there ");

replace that statement with the following statement

$("#thanks").html(result);  
// thanks is the id of your div in contact.html  and result is the what you echoed in contact.php 

thats it

i hope you get clearly

let me know if you have any doubts

Note: my apologies to members over here because i feel better by giving references to the solution than giving explanation in this requirement so i did this way

Thank you very much. But it doesnt work really, maybe i need mysql?

In any case i have this working code, but try to tweak it with some problems...

  1. I want that it is impossible to sending the contact form without any information about email.

  2. I want that you have to write 20 letters at least.

  3. It would be very nice if you dont write into the fields, the divs get red.

  4. And finally, like you can see, the thank you div is in the php file, so you can use the contact form only once, because after sending you see the php file and the form doesnt work anymore.

HTML

<section id="home-head" class="contact">     
<h1></h1>
</section>

<section id="main-content">

<div class="text-intro"><h2>CONTACT</h2></div>

<div class="columns features">
<br />
<form action="contact.php" method="post" id="contact-form" class="contact-form">
<textarea id='message' maxlength='10000' name='message' placeholder='HEllo...'>   
</textarea>
<div class='crayonico'></div>
<input class='text-input' id='senderEmail' maxlength='50' name='email' 
placeholder='E-Mail' type='email'>
<div class='emailico'></div>
<input class='btn btn-input' id='sendMessage' name='sendMessage' type='submit'  
value='SEND'>
</form>
<br /><br /><br /><br /><br />
</div>

</section>

PHP

<section id="main-content">

<div class="text-intro"><h2>KONTAKT</h2></div>

<?php
if(isset($_POST['sendMessage'])) {
$to = "info@test.com";
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'E-mail: '.$email."\n";
$from = 'Message: '.$message;
$body_message = "Question";

echo "<div id=\"submitmessage\">Thank you.</div>"; 
mail($to, $body, $from);
} else {
echo "Please check you data.";
}
?>

<div class="columns features">
<br />
<form action="contact.php" method="post" id="contact-form" class="contact-form">
<textarea id='message' maxlength='10000' name='message' placeholder='Hello...'>   
</textarea>
<div class='crayonico'></div>
<input class='text-input' id='senderEmail' maxlength='50' name='email'   
placeholder='E-Mail' type='email'>
<div class='emailico'></div>
<input class='btn btn-input' id='sendMessage' name='sendMessage' type='submit'  
value='SEND'>
</form>
<br /><br /><br /><br /><br />
</div>

Thanks so much till then.

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.