Hybrid Developer
Hybrid Developer

Reputation: 2340

Contact form not working while click on submit button

I was working with an HTML contact form, its action is a mail sending php script. But it is not working when i am clicking on the send button. I couldn't find any possible here. Please someone help me to fix this.

HTML form

<div class="contact-form">
<form action="sendmail.php" method="post">
<div class="control-group"><label class="nameLabel" for="name">Name</label> <input id="name" name="name" type="text" /></div>

<div class="control-group"><label class="emailLabel" for="email">Email</label> <input id="email" name="email" type="text" /></div>

<div class="control-group"><label class="messageLabel" for="message">Message</label><textarea id="message" name="message"></textarea></div>

<div class="control-group"><button type="submit">Send</button></div>
</form>

<h1 class="status-message-contact"></h1>
</div>

PHP code

<?php
 if(isset($_POST['submit']))
 {
    $name = $_POST['name'];
    $email = $_POST['email'];
    $query = $_POST['message'];
    $email_from = $name.'<'.$email.'>';

 $to="[email protected]";
 $subject="WEB Enquiry!";
 $headers  = 'MIME-Version: 1.0' . "\r\n";
 $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
 $headers .= "From: ".$email_from."\r\n";
 $message="   

         Name:
         $name     
         <br>
         Email-Id:
         $email        
         <br>
         Message:
         $query        

   ";
    if(mail($to,$subject,$message,$headers))
        header("Location:../index.php?msg=Successful Submission! Thankyou for contacting us.");
    else
        header("Location:../index.php?msg=Error To send Email !");
        //contact:[email protected]
 }
?>

Upvotes: 0

Views: 9070

Answers (2)

John Smith
John Smith

Reputation: 478

Replace

<button type="submit">Send</button>

with

<input type="submit" value="Send" />

And maybe add

<input type="hidden" name="submit" value="1" />

For the isset( $_POST['submit'] )

Upvotes: 0

saman khademi
saman khademi

Reputation: 842

you dont have submit button name ,change name of the button

<button name='submit' type="submit">Send</button>

or use input tag

<input name='submit' type='submit'>

Upvotes: 2

Related Questions