Reputation: 37
I'm trying to get my contact form working, but it won't work.
HTML:
<div class="container main-container">
<div class="col-md-6">
<form action="#" method="post">
<div class="row">
<div class="col-md-6">
<div class="input-contact">
<input type="text" name="name">
<span>your name</span>
</div>
</div>
<div class="col-md-6">
<div class="input-contact">
<input type="text" name="email">
<span>your email</span>
</div>
</div>
<div class="col-md-12">
<div class="input-contact">
<input type="text" name="object">
<span>object</span>
</div>
</div>
<div class="col-md-12">
<div class="textarea-contact">
<textarea name="message"></textarea>
<span>message</span>
</div>
</div>
<div class="col-md-12">
<a href="#" class="btn btn-box">Send</a>
</div>
</div>
</form>
</div>
PHP:
<?php
$name = $_POST['name'];
$email = $_POST['email'];
$object = $_POST['object'];
$message = $_POST['message'];
$formcontent="Van: $name \n Onderwerp: $object \n Bericht: $message";
$recipient = "[email protected]";
$subject = "Contact Formulier";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Er is iets fout gegaan!");
echo "Uw bericht is verstuurd, ik neem zo spoedig mogelijk contact met u op!";
?>
Could anyone help me with this? I also would like that the confirmation message is shown in a pop-up.
Thanks in advance guys, Kevin.
Upvotes: 0
Views: 177
Reputation: 389
Your form needs to be sending that POST request to the path to the .php
file. Currently, the URL for the form is going to "#". Once you send the request to the correct URL (the .php path) then it will execute that .php script which should handle things from there.
So if your file structure from web root looks something like this...
|_ .
|_ ..
|_ js/
|_ css/
|_ index.php
|_ request.php
Then you could simply point the form URL to "/request.php".
You also need a button to actually submit that form which needs to be within the <form>
tags:
<input type="submit" value="Send E-Mail">
Also, as a side note, there doesn't seem to be any form validation for that form so if you deploy that code, I'd make sure some client/server-side validation happens to make sure they can't inject <script>
tags or SQL code into the form.
Upvotes: 1