Please note that this question has been asked by several others and none of them seem to have a solution that worked for me. I just finished trying Roy's idea from his answer here without any success and hence posting yet another question. I have my contact form built using Bootstrap and I have a PHP file to field the email submission. Here's the form code:
<form class="form-horizontal" role="form" name="contact-form" id="contact-form" action="contact.php" method="post">
<div class="modal-header">
<h4>Let‘s get talking!</h4>
</div>
<div class="modal-body">
<div class="form-group">
<label for="contact-name" class="col-xs-2 control-label">Name</label>
<div class="col-xs-10">
<input type="text" class="form-control" name="contact-name" id="contact-name" placeholder="John Doe">
</div>
</div>
<div class="form-group">
<label for="contact-email" class="col-xs-2 control-label">Email</label>
<div class="col-xs-10">
<input type="email" class="form-control" name="contact-email" id="contact-email" placeholder="example@domain.com">
</div>
</div>
<div class="form-group">
<label for="contact-message" class="col-xs-2 control-label">Message</label>
<div class="col-xs-10">
<textarea class="form-control" name="contact-message" rows="5" placeholder="Your message"></textarea>
</div>
</div>
</div>
<div class="modal-footer">
<a class="btn btn-default btn-lg" data-dismiss="modal">Close</a>
<button type="submit" name="submit" id="submit" class="btn btn-primary btn-lg">Send</button>
</div>
And here's the script within contact.php
:
<?php
if (empty($_POST)) {
print "<p>No data was submitted.</p>";
print "</body></html>";
exit();
}
$name = $_POST["contact-name"];
$email = $_POST["contact-email"];
$message = $_POST["contact-message"];
$EmailTo = "amitsc@icloud.com";
$Subject = "New Message Received";
// send email
$test = mail($EmailTo, $Subject, $message, "From: ".$name." <".$email.">");
if ($test) {echo "successfuly sent";} else {echo "sending failed";}
?>
Every time I hit the Send
button in the form, it returns the message successfully sent
, however no email actually gets sent out. To make things even funnier, I still get the same message (successfully sent
) even when I submit a blank form! And that's despite the if
block at the beginning of contact.php
that is supposed to say No data was submitted
in such a scenario. What am I doing wrong?
Update: I just did a var_dump($_POST);
and here's the output on submitting a blank form:
array(4) { ["contact-name"]=> string(0) "" ["contact-email"]=> string(0) "" ["contact-message"]=> string(0) "" ["submit"]=> string(0) "" } successfuly sent
P.S.: For what it's worth, these files are currently sitting on my computer running a MAMP stack. It's not hosted on a public server yet because I'm still building it out. Could this have any bearing on the goofy results?