I am not very experiencing with php and I need help. Basically I am trying to create an appointment field so that when people fill it I get an email with the input people put.
So in the first website which is in a file called appointment.hmtl I have the following code:
<section class="section appoinment">
<div class="container">
<div class="row">
<div class="col-lg-4">
<div class="mt-3">
<div class="feature-icon mb-3">
<i class="icofont-support text-lg"></i>
</div>
<span class="h3">Need more information? Please give us a call.</span>
<h2 class="text-color mt-3">+954-225-4454 </h2>
</div>
</div>
<div class="col-lg-6 col-md-10 ">
<div class="appoinment-wrap mt-5 mt-lg-0">
<h2 class="mb-2 title-color">Book an appoinment</h2>
<p class="mb-4">Just fill out this simple form and your appointment will be reserved.</p>
<form id="#" class="appoinment-form" method="post" action="mail.php">
<div class="row">
<div class="col-lg-6">
<div class="form-group">
<select class="form-control" id="exampleFormControlSelect1">
<option>Preferred method of contact</option>
<option>Call me</option>
<option>Text me (fees may apply)</option>
<option>Email me</option>
</select>
</div>
</div>
<div class="col-lg-6">
<div class="form-group">
<input name="date" id="date" type="text" class="form-control" placeholder="dd/mm/yyyy">
</div>
</div>
<div class="col-lg-6">
<div class="form-group">
<input name="time" id="time" type="text" class="form-control" placeholder="Time">
</div>
</div>
<div class="col-lg-6">
<div class="form-group">
<input name="name" id="name" type="text" class="form-control" placeholder="Full Name">
</div>
</div>
<div class="col-lg-6">
<div class="form-group">
<input name="phone" id="phone" type="Number" class="form-control" placeholder="Phone Number">
</div>
</div>
<div class="col-lg-6">
<div class="form-group">
<input name="mail" id="mail" type="text" class="form-control" placeholder="Email">
</div>
</div>
</div>
<div class="form-group-2 mb-4">
<textarea name="message" id="message" class="form-control" rows="6" placeholder="Your Message"></textarea>
</div>
<a class="btn btn-main btn-round-full" href="Eng-confirmation.html">Make Appoinment<i class="icofont-simple-right ml-2"></i></a>
</form>
</div>
</div>
</div>
</div>
</div>
</section>
And in another file called mail.php I have the following code:
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
# FIX: Replace this email with recipient email
$mail_to = "example@gmail.com";
# Sender Data
$subject = trim($_POST["subject"]);
$sphone = trim($_POST["phone"]);
$name = str_replace(array("\r","\n"),array(" "," ") , strip_tags(trim($_POST["name"])));
$email = filter_var(trim($_POST["email"]), FILTER_SANITIZE_EMAIL);
$message = trim($_POST["message"]);
if ( empty($name) OR !filter_var($email, FILTER_VALIDATE_EMAIL) OR empty($subject) OR empty($message)) {
# Set a 400 (bad request) response code and exit.
http_response_code(400);
echo "Please complete the form and try again.";
exit;
}
# Mail Content
$content = "Name: $name\n";
$content = "Topic: $subject\n";
$content = "Phone: $phone\n";
$content .= "Email: $email\n\n";
$content .= "Message:\n$message\n";
# email headers.
$headers = "From: $name <$email>";
# Send the email.
$success = mail($mail_to,$content, $headers);
if ($success) {
# Set a 200 (okay) response code.
http_response_code(200);
echo "Thank You! Your message has been sent.";
} else {
# Set a 500 (internal server error) response code.
http_response_code(500);
echo "Oops! Something went wrong, we couldn't send your message.";
}
} else {
# Not a POST request, set a 403 (forbidden) response code.
http_response_code(403);
echo "There was a problem with your submission, please try again.";
}
?>
However, when I test the website and fill the field I never receive the mail with the information. This code is taken from a free template website so I know is kind of right, but there is something else I a missing or need to add for it to work.
Thousands thanks to the kind soul that help me make this work.
Aucun commentaire:
Enregistrer un commentaire