I wrote a simple php script for a form, tested it out, and worked as expected. But when I actually added the script into the original project that I am working on, it suddenly stopped working? I am sure it has nothing to do with the php script as for it worked properly when I tested it; so basically what I am thinking about is that I probably wrote the action attribute wrong? I am pretty sure it is a rookie mistake. Eventually, I am really new to php.
Regards.
HTML code:
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="exampleModalLabel">New message</h4>
</div>
<div class="modal-body">
<form action="contact.html" method="post">
<div class="form-group">
<label name="email" class="control-label">Email:</label>
<input type="text" class="form-control" id="recipient-name">
</div>
<div class="form-group">
<label name="phone" class="control-label">Phone:</label>
<input type="text" class="form-control" id="recipient-mobile">
</div>
<div class="form-group">
<label name="message" class="control-label">Message:</label>
<textarea class="form-control img-responsive" rows="5" id="messageText"></textarea>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" id="resetText" class="btn btn-default">Reset</button>
<input type="button" value="Send message" name="send" class="btn btn-danger colorbg"/>
</div>
</div>
</div>
</div>
PHP Code:
<?php
if(isset($_POST['send'])){
$to = 'domain@mail.com';
$subject = 'Solutions';
$mail = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$mailHeader = "From: $mail \r\n Phone: $phone";
$formcontent="Message: $message";
if (!filter_var($mail, FILTER_VALIDATE_EMAIL)) {
echo "<script language='javascript'>
alert('E-mail address is not valid');
var email = document.getElementById('recipient-name');
email.className += ' border-red';
</script>";
} else {
echo "<script language='javascript'>
var email = document.getElementById('recipient-name');
email.className = '';
email.className += ' form-control';
</script>";
if (mail($to , $subject, $formcontent, $mailHeader)) {
echo "<script>
window.setTimeout(function () {
window.location.href = 'test.html';
}, 3000);
</script>";
} else {
echo "<script language='javascript'>alert('There was an error. Please try again.')</script>";
}
}
}
?>
Please note that I uploaded the project on my website in order to actually test the script so the link is something like this: website.com/project/index.html. And I changed the action to action="script/contact.php"
, action="./script/contact.php
, action="contact.php"
none worked.