简体   繁体   中英

how to link a second Html form to php on

please could someone please help me figure out why my code is not working. I have linked up the first form in html to a process.php and it works like a bomb but the second form which is just a name and email send through form is not working, it gets stuck on the processTwo.php I am not familiar with writing if statements so I kept it simple and wrote a secondprocess.php which I labeled processTWO.php but as I said it gets stuck at the processTwo.php page and doesn't parse through to my success page, could some one be as kind as to help me figure this out, I have some attached some pics of the code as well as code snippet below enter image description here below is the html form code

  <section>

    <div class="row">
      <div class="col-lg-12 col-md-12 col-sm-12  d-flex justify-content-center flex-row subscribe-form">
        <div class="container">
          <div class="col-12">
            <div class="col-lg-12 col-md-12 col-sm-12 ">
              <form class=" py-5 text-center" action="processTwo.php" method="POST">
                <input type="type" class="form-subscribe" name="nameTwo" placeholder=" Name:" id="name_two">
                <div class="col-lg-12 col-md-12 col-sm-12 ">
                  <input type="email" class="form-subscribe-2" name="emailTwo" placeholder=" Email:" id="email_two">
                  <br>
                  <button type="submitTwo" class="btn btn-reg">Register</button>
                </div>

              </form>
            </div>
          </div>
        </div>
        <div class="subscribe-book-arrow"></div>
      </div>
    </div>
    </div>

  </section>

and here is the php code

 <?php

if (isset($_POST['submitTwo'])) { //Email information

$name_One= $_POST['nameTwo'];
$email_One = $_POST['emailTwo'];


$mailTo_Two = "Insp....@hotmail.com";
$text = "you have received a Registration e-mail from ".$name_One.".\n";

//send email

mail( $mailTo_Two, $text, $name_One,  $email_One);

header('Location: http://m.......co.za/success.html');

}

First of all your html button has a wrong type attribute and no name attribute. If in doubt, your form will never reach the PHP file. Just use a button in the following way:

<button type="submit" name="submitTwo" class="btn btn-reg">Register</button>

You are using the mail function with the wrong parameters. As stated out in the PHP documentation, you have to mention recipient, subject and text. You 're using recipient, message, name and an email address.

Here is an example from the php documentation:

<?php
$to      = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
    'Reply-To: webmaster@example.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);

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