PHP form not responding

2023 views php
6

I am trying to make a simple php contact form for my html page, below I have the code inside my html

<div  class="container" id="contact">
   <form action="form.php" method="post">
     Name: <input type="text" name="name" placeholder="Name"> 
    <br>
     E-mail: <input type="text" name="email" placeholder="Email"> 
    <br>
     Message: <textarea name="message" rows="8" cols="80" placeholder="Type message here"></textarea>
     <input type="submit">
   </form>
 </div>

and here below is my php file

<?
  if (isset($_POST['submit']) {
    // code...
    $name = $POST['name'];
    $emailFrom = $POST['email'];
    $message = $POST['message'];

    $mailTo = "oscar@cleveroscar.com";
    $headers = "From ".$emailFrom;
    $txt = "You got an email from".$name."\n\n".$message ;

    mail($mailTo, $txt, $headers);
    header("Location: index.php?mailsend");
  }

/?>

I went into the dev tools to try and figure out the issue and this is the error I receive "POST https://cleveroscar.com/form.php 405" (the url is my portfolio site"

I am a self-taught developer so my apologies if I didnt explain the question properly

answered question

try putting die('Got here..'); at the very top of your form.php file to see if you are reaching it. if not maybe your path is wrong

Proper PHP tags are <?php and ?> (Not <? /?>)

@dustytrash good catch I didn't even notice that

Always $_POST not $POST

Yea I didn't even notice I had a syntax error, good eye I will be adding these suggestions now and test it, will give you guys the results in just a sec

@OscarPacheco you know, it would be simpler if you got yourself an IDE with proper symbolic debugging. Much more efficient than a Q/A rampage here. If you value your time and the quality of what you learn, take the time to get one going and working in your development stack.

1 Answer

11

Your submit input tag has to have a name.

Change:

<input type="submit">

To:

<input type="submit" name="submit">

And for the form values to be retrieved properly in your PHP file:

Change:

$POST

To:

$_POST

posted this

Have an answer?

JD

Please login first before posting an answer.

Ads

Categories