This question already has an answer here:
i recentlly uploaded my website and am having trouble getting my form to work. can someone help me out. Before I was getting an HTTP 500 error, and I realized I had a type in my code, but since I fixed it, I'm not getting any error, however Im also not receiving any emails upon submitting my form. can someone let me know what I did wrong ?!
<?php
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$mailFrom = $_POST['mail'];
$message = $_POST['message'];
$mailTo = "info@orbitwebdesign.ca";
$headers = "From: ".$mailFrom;
$txt = "You have recieved an e-mail from ".$name.".
".$message;
mail($mailTo, $subject, $txt, $headers);
header("Location: contact.php?mailsend");
}
?>
<section class="section-form" id="contact">
<div class="row">
<h2>BOOK A FREE CONSULTATION!</h2>
</div>
<div class="row">
<form method="POST" action="contact.php" class="contact-form">
<div class="row">
<div class="col span-1-of-3">
<label for="name">Name</label>
</div>
<div class="col span-2-of-3">
<input type="text" name="name" id="name" placeholder="Your name" required>
</div>
</div>
<div class="row">
<div class="col span-1-of-3">
<label for="mail">Email</label>
</div>
<div class="col span-2-of-3">
<input type="email" name="email" id="email" placeholder="Your email" required>
</div>
</div>
<div class="row">
<div class="col span-1-of-3">
<label>Message</label>
</div>
<div class="col span-2-of-3">
<textarea name="message" placeholder="Your message"></textarea>
</div>
</div>
<div class="row">
<div class="col span-1-of-3">
<label> </label>
</div>
<div class="col span-2-of-3">
<input class="input-btn" name="submit" type="submit" value="Send">
</div>
</div>
</form>
</div>
</section>
</div>
Sometimes, the mail
command is locked by the provider. You can try the following to get more information:
$success = mail('example@example.com', 'My Subject', $message);
if (!$success) {
$errorMessage = error_get_last()['message'];
}
Taken from here
Or use a dedicated class like PHPMailer or similar.
the email address is stored in $_POST['email']
. but, in your contact.php, row 5:
$mailFrom = $_POST['mail'];
Try replacing $_POST['mail']
with $_POST['email']
Hope it helps.
ps Also the label in your html code is for 'mail' too instead for 'email' like the input tag