Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send data from HTML form to php

Tags:

html

post

php

I am trying to send data from HTML to PHP. Here is my html code:

<div class="content">
    <form action="email-script.php" method="post">
      <div class="contact-form mar-top30">
        <label> <span>Full name</span>
        <input type="text" class="input_text" name="name" id="name"/>
        </label>
        <label> <span>Email</span>
        <input type="text" class="input_text" name="email" id="email"/>
        </label>
        <label> <span>Subject</span>
        <input type="text" class="input_text" name="subject" id="subject"/>
        </label>
        <label> <span>Message</span>
        <textarea class="message" name="feedback" id="feedback"></textarea>
        </label>
        <label>
                <input type="submit" class="button" value="Send" />
        </label>
      </div>
    </form>
  </div>

And here is my php code:

<!DOCTYPE html>
<html>
<?php
    $email=$_POST["email"];
    $subject = $_POST["subject"];
    $message = $_POST["name"] . "Sent this email" . "\r\n" . $_POST["feedback"] . "Sent from this email address:" . $_POST["email"];
    mail("[email protected]", $subject, $message);
    //header("Location: index.html");
?>
Error, please contact Jack at ([email protected]) <br>
email: <?php $email ?> <br>
subject: <?php $subject ?> <br>
message: <?php $message ?> <br>
</html>

I was thinking the best way to do this was through a POST method. How do I go about sending all of the data from the html form to the php email script via the click of the submit button. Posted below are screenshots of the issue.

Before submit: enter image description here

After submit:
enter image description here

like image 529
Jsleshem Avatar asked May 17 '26 13:05

Jsleshem


1 Answers

just add echo before your output variables

email: <?php echo $email ?> <br>
subject: <?php echo $subject ?> <br>
message: <?php echo $message ?> <br>
like image 153
wahdan Avatar answered May 19 '26 01:05

wahdan