Hi, i have a bootstrap site, but when i send the email by the contact form the system show me a white blank page (contact.php) with the message “Contact form successfully submitted. Thank you, I will get back to you soon!”, i don’t want this but i want to show the page contact.html.
This is the html code:
<form id="contact-form" method="post" action="contact.php" role="form">
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label for="firstname" class="control-label">Nome</label>
<input id="firstname" name="name" type="text" class="form-control">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label for="lastname" class="control-label">Cognome</label>
<input id="lastname" name="surname" type="text" class="form-control">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label for="email" class="control-label">Email</label>
<input id="email" name="email" type="text" class="form-control">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label for="subject">Oggetto in breve</label>
<input id="subject" name="subject" type="text" class="form-control">
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-sm-12">
<div class="form-group">
<label for="message" class="control-label">Messaggio</label>
<textarea id="message" name="message" class="form-control"></textarea>
<div class="help-block with-errors"></div>
</div>
</div>
<div class="col-sm-12">
<button type="submit" class="btn btn-primary"><i class="fa fa-envelope-o"></i> Invia il messaggio</button>
</div>
</div>
</form>
And this is contact.php:
<?php
// an email address that will be in the From field of the email.
$from = 'Demo contact form <email@gmail.com>';
// an email address that will receive the email with the output of the form
$sendTo = 'Demo contact form <email@gmail.com>';
// subject of the email
$subject = 'New message from contact form';
// form field names and their translations.
// array variable name => Text to appear in the email
$fields = array('name' => 'Nome', 'surname' => 'Cognome', 'email' => 'Email', 'subject' => 'Oggetto', 'message' => 'Messaggio');
// message that will be displayed when everything is OK :)
$okMessage = 'Contact form successfully submitted. Thank you, I will get back to you soon!';
// If something goes wrong, we will display this message.
$errorMessage = 'There was an error while submitting the form. Please try again later';
// if you are not debugging and don't need error reporting, turn this off by error_reporting(0);
error_reporting(E_ALL & ~E_NOTICE);
try
{
if(count($_POST) == 0) throw new \Exception('Form is empty');
$emailText = "You have a new message from your contact form\n=============================\n";
foreach ($_POST as $key => $value) {
// If the field exists in the $fields array, include it in the email
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,
);
// Send email
mail($sendTo, $subject, $emailText, implode("\n", $headers));
$responseArray = array('type' => 'success', 'message' => $okMessage);
}
catch (\Exception $e)
{
$responseArray = array('type' => 'danger', 'message' => $errorMessage);
}
// if requested by AJAX request return JSON response
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 just display the message
else {
echo $responseArray['message'];
}
I do not understand what to change to stay on contact.html and do not show the white page with the success message, I’m a beginner.