Alex Nowak Alex Nowak - 3 days ago 5
HTML Question

The contact form does not work

I purchased a template, but there was no mailer file included, I'm trying to get this working. This is the form:

<div class="row">
<div class="col-sm-6">
<div class="well">
<form id="contactForm" data-toggle="validator" class="shake" action="mailer.php" method="post">

<div class="form-group"><!-- ENTER MANE -->
<input type="text" name="name" class="form-control" id="name" placeholder="Enter name" required data-error="NEW ERROR MESSAGE">
<div class="help-block with-errors"></div>
</div>

<div class="form-group"><!-- ENTER EMAIL -->
<input type="email" name="email" class="form-control" id="email" placeholder="Enter email" required>
<div class="help-block with-errors"></div>
</div>

<div class="form-group"><!-- ENTER MESSAGE -->
<textarea id="message" name="message" class="form-control" rows="5" placeholder="Enter your message" required></textarea>
<div class="help-block with-errors"></div>
</div>

<!-- button form submit -->
<div class="submit">
<!-- <button id="form-submit" name="submitted" class="btn btn-default btn-lg">Submit</button> -->
<input id="form-submit" name="submitted" class="btn btn-default btn-lg" type="submit" value="Submit">
<div id="msgSubmit" class="h5 h5 text-danger hidden"></div>
<div class="clearfix"></div>
</div>

</form>


And here's the old mailer file that I purchased with a different template:

<?php
$email_to = "example@domain.com"; // write your email here, or email where it has to be sent
$name = $_POST["name"];
$email = $_POST["email"];
$message = $_POST["message"];
$text = "NAME: $name<br>
EMAIL: $email<br>
MESSAGE: $message";
mail($email_to, "Subject", $text);
?>


Why is this not working?

Answer

It seems like email where it should be sent is wrong. Set correctly $email_to variable with email where you want to receive messages.

Also with mail() you dont have to set headers. You can simplify it:

<?php
$email_to = "example@domain.com"; // write your email here, or email where it has to be sent
$name = $_POST["name"];
$email = $_POST["email"];
$message = $_POST["message"];
$text = "NAME: $name<br>
         EMAIL: $email<br>   
         MESSAGE: $message";
mail($email_to, "Subject", $text);
?>

Also I wouldn't use in your case validator which you don't understand and is taken from another site.

There might be a problem with your button in HTML looks like submit should be done by JavaScript. If not you should change

<button id="form-submit" name="submitted" class="btn btn-default btn-lg">Submit</button>

to

<input id="form-submit" name="submitted" class="btn btn-default btn-lg" type="submit" value="Submit">

Debug

if you are getting an empty message try:

echo "<pre>";
print_r($_POST);

to check what is inside $_POST array.


Manual

PHP: mail

Comments