简体   繁体   中英

php contact form not responding on clicking submit button

I have a form in php with the below code:

 <form action="" method="post" class="wpcf7-form"> <p><label> Your Name<br /> <span><input type="text" name="your-name" value="" size="40" required /></span> </label></p> <p><label> Your Email<br /> <span><input type="email" name="your-email" value="" size="40" required /></span> </label></p> <p><label> Your Message<br /> <span><textarea name="your-message" cols="40" rows="10" required></textarea></span> </label></p> <p><input type="submit" value="Submit" name="submit" /></p> </form> <?php if(isset($_POST['submit'])){ $to = "contact@ghem.com"; // this is your Email address $from = $_POST['your_email']; // this is the sender's Email address $first_name = $_POST['your_name']; $last_name = $_POST['your_message']; $subject = "Contact"; $subject2 = ""; $message = $first_name. " has sent you the following message. Message:". "\n\n". $last_name. "\n\n"."Email: ".$from. "\n\n"; $headers = "From:". $from; $headers2 = "From:". $to; mail($to,$subject,$message,$headers); // mail($last_name,$subject2,$message2,$headers2); // sends a copy of the message to the sender echo '<div style="color:#5cad2f; "><b>Thank you '. $first_name. ', we will contact you shortly.</b></div>'; // You can also use header('Location: thank_you.php'); to redirect to another page. }?>

when I enter details and click submit button, nothing is happening, can anyone please help me with this?

Try to know your value is set or not like:

<?php 
     if(isset($_POST['submit']))
     {
          echo "hello world";
     }
?>

when you click submit button if it display hello world that means submit work after that replace name as you show in your input field with $_POST['your_name']

You should use same input name while getting POST values

$from = $_POST['your-email'];
 $first_name = $_POST['your-name'];
 $last_name = $_POST['your-message'];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM