I'm trying to create a simple form that when filled out sends me a specific email. The website definitely registers the click and tells me that my message was sent, but no email ever comes.
If I, however, get rid of the if-statement, it does send me an email, but only when I refresh the page, so it doesn't send me any of the relevant information. So, my if-statement is wrong, but when I change it to strlen($name)!=0
, it still doesn't send me the email.
I think the problem is that when I click the button, it doesn't run the php code. How do I fix this? Thanks.
Here is my code:
<form method="post" id="contactForm" name="sentMessage" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<input type="text" class="form-control" placeholder="Your Name *" id="name" required data-validation-required-message="Please enter your name.">
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="email" class="form-control" placeholder="Your Email *" id="email" required data-validation-required-message="Please enter your email address.">
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="tel" class="form-control" placeholder="Your Phone *" id="phone" required data-validation-required-message="Please enter your phone number.">
<p class="help-block text-danger"></p>
</div>
</div>
<div class="col-md-6">
<div class="form-group">
<textarea class="form-control" placeholder="Your Message *" id="message" required data-validation-required-message="Please enter a message."></textarea>
<p class="help-block text-danger"></p>
</div>
</div>
<div class="clearfix"></div>
<div class="col-lg-12 text-center">
<div id="success"></div>
<button type="submit" id="submit" class="btn btn-xl">Send Message</button>
</div>
</div>
<?php
$name=$_POST["name"];
$email=$_POST["email"];
$phone=$_POST["phone"];
$message=$_POST["message"];
if(isset($_POST["submit"])){
$message=$message."\nSent by".$name." whose phone number is ".$phone."and whose email is".$email;
mail("myemail@gmail.com","title","let's try this message.".$message);
}
?>