Submit button for my contact form is not submittin

2019-06-26 03:12发布

I'm working on my second website and throughout creating this one and my first the people here on StackOverflow have been an amazing help. I can just browse and find almost anything I wan't to know. 99% of problems I've had, I fixed with answers I've read on here. So first of thank you all so much!

This is the first time I'm posting something because I'm not able to find the specific answer for my code. There are people one here with the same problems but when I look at their code I'm just lost. I know html a fair bit by now. It's the php that I'm clueless about. I'm not looking for something fancy, I'm just trying to create a simple contact form.

So here is my question and code, I hope some of you are able to help me.

I used an PHP code from a youtube tutorial and it's deadeasy (as said before: first time PHP) yet I can't get it to work. Although I'm doing everything the same as the man in the clip. He shows his is working so I'm extremely curious as to way mine is not?

My form does not 'send' and after clicking the submit button I don't get the 'thank you' line.

here is the html:

<form method="post" action="contactform" name="contactform" id="contactform">

            <ol>
                <li>
                    <label for="voornaam">Voornaam</label>
                    <input type="text" name="voornaam" />
                </li>
                <li>
                    <label for="achternaam">Achternaam</label>
                    <input type="text" name="achternaam" />
                </li>

                <li>
                    <label for="telefoon">Telefoon Nummer</label>
                    <input type="text" name="telefoon" />
                </li>
                <li>
                    <label for="email">E-mail Adres</label>
                    <input type="text" name="email" />
                </li>
                <li>
                    <label for="bericht">Type hier je bericht</label>
                    <textarea name="bericht"></textarea>
                </li>
                <li>
                    <input name="submit" type="submit" value="submit" />
                    <input name="reset" type="reset" value="reset" />                    
                </li>

            </ol>

            </form>

and the PHP:

<?php

$voornaam = $_POST ['voornaam'];
$achternaam = $_POST ['achternaam'];
$telefoon = $_POST ['telefoon'];
$email = $_POST ['email'];
$bericht = $_POST ['bericht'];

$to = "felicevancuyk@gmail.com";
$subject = "dkl groep bericht";

mail ($to, $subject, $bericht, "From " . $voornaam . $achternaam . $telefoon};
echo "Bedankt. We nemen zo snel mogelijk contact met u op.";

?>

2条回答
趁早两清
2楼-- · 2019-06-26 03:43

You have to just change your action attribute of first line of code to the page where you want to process your form. It may be the same page but it is recommend to be on another page. Here is an example to submit the form in the same page:

   <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" name="contactform" id="contactform">

Don't forget if you are submitting on the same page as like the above example then your page should be in .php extension otherwise it will not work.

查看更多
手持菜刀,她持情操
3楼-- · 2019-06-26 03:49

It could be that your action is not set correctly:

<form method="post" action="contactform" name="contactform" id="contactform">

This action tag is the URL that the form is sent to. In the above example you gave, it doesn't appear to be a file name. You want it to be something like this:

<form method="post" action="http://mysite.com/process-form.php" name="contactform" id="contactform">

Also note that in your example PHP code you are emailing responses to the form without cleaning those responses. Someone could send malicious code to your server if you don't clean the data first.

Something like:

$cleaned_voornaam = preg_replace("/[^ 0-9a-zA-Z]/", "_", $_POST['voornaam']);

Good luck!

查看更多
登录 后发表回答