I just installed a fresh version of Ubuntu 14.04 Server on one of my computers. I installed everything to make it run like a typical web server (including PHP). My problem is, I have a contact form written in PHP that I'm running on my site and in it, I have a fail safe in case something goes wrong with submitting the form, which is what is happening. The script runs fine on any other server. But on mine, it goes to my message failed function every time I try to submit the form. I happen to think it's something wrong with the way PHP is configured on my server. Any ideas?
Here is the PHP script if anyone wants to test it:
<?php
$field_name = trim($_POST['cf_name']);
$field_email = trim($_POST['cf_email']);
$field_subject = trim($_POST['cf_subject']);
$field_message = trim($_POST['cf_message']);
if (empty($field_name) && empty($field_email) && empty($field_subject) && empty($field_message) && !preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $field_email))
{
?>
<script language="javascript" type="text/javascript">
alert('One or more fields are invalid. Please fill out any empty fields and make sure your email address is valid.');
window.location = 'contact.html';
</script>
<?php
}
else if(empty($field_name))
{
?>
<script language="javascript" type="text/javascript">
alert('Please type in your name.');
window.location = 'contact.html';
</script>
<?php
}
else if(empty($field_email))
{
?>
<script language="javascript" type="text/javascript">
alert('Please type an email address.');
window.location = 'contact.html';
</script>
<?php
}
else if(empty($field_subject))
{
?>
<script language="javascript" type="text/javascript">
alert('Please type a subject.');
window.location = 'contact.html';
</script>
<?php
}
else if(empty($field_message))
{
?>
<script language="javascript" type="text/javascript">
alert('Please type a message.');
window.location = 'contact.html';
</script>
<?php
}
else if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $field_email))
{
?>
<script language="javascript" type="text/javascript">
alert('Please enter a valid email address.');
window.location = 'contact.html';
</script>
<?php
}
else
{
$mail_to = '[email protected]';
$subject = "New message from...";
$body_message .= 'A message from a user of...'."\n\n";
$body_message .= 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Subject: '.$field_subject."\n";
$body_message .= 'Message: '.$field_message;
$headers = "From:";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) {
?>
<script language="javascript" type="text/javascript">
alert('Thanks for contacting me! I will respond as soon as possible.');
window.location = 'contact.html';
</script>
<?php
} else {
?>
<!-- This is triggering every time I submit the form -->
<script language="javascript" type="text/javascript">
alert('Message failed. Please try again later.');
window.location = 'contact.html';
</script>
<?php
}
}
?>
Edit
The hosting side of things works fine.