A
Anonymous
Guest
Hi there,
I have a contact form on a website and when filled out, no email is being sent to the designated email I assigned.
When filled out, the page goes to the home page as stated in the code but that is the only thing it is doing correctly.
Below is what I have for my PHP file.
Below is what I have in my HTML file.
Please let me know what I need to fix. Thank you for your time!
I have a contact form on a website and when filled out, no email is being sent to the designated email I assigned.
When filled out, the page goes to the home page as stated in the code but that is the only thing it is doing correctly.
Below is what I have for my PHP file.
Code:
<?php
// Define some constants
define( "RECIPIENT_NAME", "John Doe" );
define( "RECIPIENT_EMAIL", "myemail@yahoo.com" );
define( "EMAIL_SUBJECT", "Subject" );
$success = true;
$senderName = isset( $_POST['name'] ) ? preg_replace( "/[^\.\-\' a-zA-Z0-9]/", "", $_POST['name'] ) : "";
$senderEmail = isset( $_POST['email'] ) ? preg_replace( "/[^\.\-\_\@a-zA-Z0-9]/", "", $_POST['email'] ) : "";
$original_message = isset( $_POST['message'] ) ? preg_replace( "/(From:|To:|BCC:|CC:|Subject:|Content-Type:)/", "", $_POST['message'] ) : "";
$message = 'Name: '.$senderName.'<br/>Email: '.$senderEmail.'<br/>Message: '.$original_message;
if ( $senderName && $senderEmail && $message ) {
$recipient = RECIPIENT_NAME . " <" . RECIPIENT_EMAIL . ">";
$headers = "From: " . $senderName . " <" . $senderEmail . ">\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: text/HTML; charset=ISO-8859-1\n";
$success = mail( $recipient, EMAIL_SUBJECT, $message, $headers );
}
if ( $success )
{
?>
<script>
window.location='index.html';
</script>
<?php
}
else
{
echo "<h1>Test, test.</h1>";
}
?>
Below is what I have in my HTML file.
Code:
<section id="contact" class="contact page-section add-top add-bottom">
<section class="inner-section">
<section class="container">
<div class="row">
<article class="col-md-12 text-center">
<h1 class="main-heading main-heading">Contact Us</h1>
<div class="liner"><span></span></div>
<p class="promo-text white-text">For any questions or comments, please complete our form below or give us a call us.</p>
</article>
</div>
<div class="row">
<article class="col-md-12 text-center">
<div class="alert alert-error error" id="fname">
Name must not be empty
</div>
<div class="alert alert-error error" id="fmail">
Please provide a valid email
</div>
<div class="alert alert-error error" id="fmsg">
Message should not be empty
</div>
</article>
</div>
<form name="myform" action="sendcontact.php" enctype="multipart/form-data" method="post">
<div class="row add-top-small animated" data-fx="pulse">
<article class="col-md-6">
<input type="text" placeholder="Name" id="name" name="name" size="100">
<input type="text" placeholder="Email" name="email" id="email" size="30">
<textarea placeholder="Message" name="message" cols="40" rows="3" id="msg"></textarea>
</article>
<article class="col-md-2">
<button class="btn btn-rounded" id="submit" name="submit" type="submit">Go</button>
</article>
</div>
</form>
</section>
</section>
</section>