I am having problem with this contact form I can't get this to work please help? I was working with an HTML contact form, its action is a mail sending php script. But it is not working when i am clicking on the send button. Please someone help me to fix this.
This is contact.php
<?php
// configure
$from = 'Demo contact form <demo@domain.com>';
$sendTo = 'info@leonardorinaldi.io'; // Add Your Email
$subject = 'New message from contact form';
$fields = array('name' => 'Name', 'subject' => 'Subject', 'email' => 'Email', 'message' => 'Message'); // array variable name => Text to appear in the email
$okMessage = 'Contact form successfully submitted. Thank you, I will get back to you soon!';
$errorMessage = 'There was an error while submitting the form. Please try again later';
// let's do the sending
try
{
$emailText = "You have new message from contact form\n=============================\n";
foreach ($_POST as $key => $value) {
if (isset($fields[$key])) {
$emailText .= "$fields[$key]: $value\n";
}
}
$headers = array('Content-Type: text/plain; charset="UTF-8";',
'From: ' . $from,
'Reply-To: ' . $from,
'Return-Path: ' . $from,
);
mail($sendTo, $subject, $emailText, implode("\n", $headers));
$responseArray = array('type' => 'success', 'message' => $okMessage);
}
catch (\Exception $e)
{
$responseArray = array('type' => 'danger', 'message' => $errorMessage);
}
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
$encoded = json_encode($responseArray);
header('Content-Type: application/json');
echo $encoded;
}
else {
echo $responseArray['message'];
}
This is the html section of the website:
<!--====== Contact ======-->
<section id="contact" class="contact section-padding">
<div class="contact-overlay"></div>
<!-- section header -->
<div class="text-center mb-50">
<h4 class="tit tit-center">GET IN TOUCH</h4>
</div>
<div class="contact-item container">
<div class="row">
<!-- contact form -->
<div class="col-md-8 col-md-offset-2">
<div class="form" id="contact-form" method="post" action="contact.php">
<div class="messages"></div>
<div class="controls">
<div class="col-sm-6">
<div class="form-group">
<input id="form_name" type="text" name="name" placeholder="Name *" required="required" data-error="Firstname is required.">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<input id="form_email" type="email" name="email" placeholder="Email *" required="required" data-error="Valid email is required.">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-sm-12">
<div class="form-group">
<input id="form_subject" type="text" name="subject" placeholder="Subject">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-sm-12">
<div class="form-group">
<textarea id="form_message" name="message" placeholder="Message *" rows="4" required="required" data-error="Message."></textarea>
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-sm-12">
<input type="submit" class="button" value="Send Message">
</div>
<div class="clear-fix"></div>
</div>
</div>
</div>
</div>
</div>
</section>
<!--====== End Contact ======-->
Can someone please help me? there are errors?