简体   繁体   中英

contact form not sending / redirecting

Hi I have the below codes , and for some reason redirects and I get a Undefined variable: subject in C:\\wamp\\www\\boot\\send.php on line 42, as below. Appreciate any assistance I can get.

Line 42 is

$go = mail($to, $subject, $body, "From:<$from>");

Contact us

    <body>
<div class='formbody'>

<link href='http://fonts.googleapis.com/css?family=Lato' rel='stylesheet' type='text/css'>

<form id="contact-form" action="send.php" method="POST">

  <p>Dear hidden@gmai..com,</p>
  <p>My
    <label for="your-name">name</label> is
    <input type="text" name="your-name" id="your-name" minlength="3" placeholder="(your name here)" required> and</p>

  <p>my
    <label for="email">email address</label> is
    <input type="email" name="your-email" id="email" placeholder="(your email address)" required>
  </p>

  <p> I have a
    <label for="your-message">message</label> for you,</p>

  <p>
    <textarea name="your-message" id="your-message" placeholder="(your msg here)" class="expanding" required></textarea>
  </p>
  <p>
    <button type="submit">
      <svg version="1.1" class="send-icn" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="100px" height="36px" viewBox="0 0 100 36" enable-background="new 0 0 100 36" xml:space="preserve">
        <path d="M100,0L100,0 M23.8,7.1L100,0L40.9,36l-4.7-7.5L22,34.8l-4-11L0,30.5L16.4,8.7l5.4,15L23,7L23.8,7.1z M16.8,20.4l-1.5-4.3
    l-5.1,6.7L16.8,20.4z M34.4,25.4l-8.1-13.1L25,29.6L34.4,25.4z M35.2,13.2l8.1,13.1L70,9.9L35.2,13.2z" />
      </svg>
      <small>SEND PLEASE</small>
    </button>
  </p>
</form>
    <script src="assets/js/jquery.min.js"></script>
    <script src="assets/bootstrap/js/bootstrap.min.js"></script>
    <script src="assets/js/bs-animation.js"></script>
     <script src="assets/js/index.js"></script>
    </div>
</body>

Send.php

    <?php
$to = "hidden@gmail.com";
$name = TRIM (stripslashes($_POST['your-name']));
$email = TRIM (stripslashes($_POST['your-email']));
$message = TRIM (stripslashes($_POST['your-message']));

$body ="";
$body .="Name: ";
$body .=$name;
$body."\n";

$body ="";
$body .="Email: ";
$body .=$email;
$body."\n";

$body ="";
$body .="Message: ";
$body .=$message;
$body."\n";


$go = mail($to, $subject, $body, "From:<$from>");

if($go) {

    print("message sent");
}

else{

    print("There has been a small error . Sorry!!");
}

?>

You'll want to condense the 2 form tags:

<form id="contact-form">
<form action="send.php" method="post">

into one:

<form id="contact-form" action="send.php" method="post">

Remove <form id="contact-form"> . It's causing an extra form which doesn't exist. Try changing it to a div , or putting it in your other form tag, then it'll work fine.

The reason it's not directing you to the send.php is caused by the two form tags. The first form tag will run first and be the reason why it's staying on the same page. To stop this confusion you could give the form an id (like class) using the div tag:

<div id="contact-form">
<form action="send.php" method="post">

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