I checked so many posts on here but I am unable to fix this. I have a PHP form and although the email is sent it doesn't show any massage and I don't know what I am missing.
In the PHP it mentions a success and failed but no reference on where that message sits? I set up PHP forms before but this is throwing me off.
Anyone can help, please?
The sendmail.php code
<?php
// Define some constants
define( "RECIPIENT_NAME", "Email" );
define( "RECIPIENT_EMAIL", "email@email.com" );
// Read the form values
$success = false;
$senderName = isset( $_POST['username'] ) ? preg_replace( "/[^\s\S\.\-\_\@a-zA-Z0-9]/", "", $_POST['username']) : "";
$senderEmail = isset( $_POST['email'] ) ? preg_replace( "/[^\.\-\_\@a-zA-Z0-9]/", "", $_POST['email'] ) : "";
$message = isset( $_POST['message'] ) ? preg_replace( "/(From:|To:|BCC:|CC:|Subject:|Content-Type:)/", "", $_POST['message'] ) : "";
// If all values exist, send the email
if ( $senderName && $senderEmail && $message) {
$recipient = RECIPIENT_NAME . " <" . RECIPIENT_EMAIL . ">";
$headers = "From: " . $senderName . "";
$msgBody = " Email: ". $senderEmail . " Message: " . $message . "";
$success = mail( $recipient, $headers, $msgBody );
//Set Location After Successsfull Submission
header('Location: contact.html?message=Successfull');
}
else{
//Set Location After Unsuccesssfull Submission
header('Location: contact.html?message=Failed');
}
?>
The HTML code of the contact.html:
<!--Contact Section-->
<section class="contact-section">
<div class="auto-container">
<div class="info-container">
<div class="row clearfix">
</div>
</div>
<div class="contact-container">
<div class="row clearfix">
<!--Form-->
<div class="form-column col-lg-6 col-md-12 col-sm-12">
<div class="inner wow fadeInLeft" data-wow-delay="0ms" data-wow-duration="1500ms">
<div class="sec-title">
<h2>Send <strong>Your Message</strong></h2>
<div class="lower-text">Don’t Hesitate to Contact Us</div>
</div>
<div class="default-form contact-form">
<form method="post" id="contact-form" action="sendemail.php">
<div class="row clearfix">
<div class="form-group col-lg-6 col-md-6 col-sm-12">
<div class="field-label">Name</div>
<div class="field-inner">
<input type="text" name="username" placeholder="Your Name" required="" value="">
</div>
</div>
<div class="form-group col-lg-6 col-md-6 col-sm-12">
<div class="field-label">Email</div>
<div class="field-inner">
<input type="email" name="email" placeholder="Email Address" required="" value="">
</div>
</div>
<div class="form-group col-lg-12 col-md-12 col-sm-12">
<div class="field-label">Message</div>
<div class="field-inner">
<textarea name="message" placeholder="Write your message..." required=""></textarea>
</div>
</div>
<div class="form-group col-lg-12 col-md-12 col-sm-12">
<button type="submit" class="theme-btn btn-style-three"><span class="btn-title">Send Your Message</span></button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
Thank you anyone who can help. :)
Aucun commentaire:
Enregistrer un commentaire