Hi,
I am working on a simple script for capturing data from my form, enter it into a table and then send to an email distribution list. The script worked on my company testserver but I cannot seem to get it to work on a free webhost. It doesnt throw any error despite E_ALL being on…
Would appreciate if someone could look over the script and give me some suggestions, I suspect the error to be related to the mail() function but am not sure.
<html>
<head> </head>
<body>
<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL);
if(isset($_POST['name'])) {
// CHANGE THE TWO LINES BELOW
$email_to = "[email protected]";
$email_from = "[email protected]";
$email_subject = "DADHA - Guest Problem Alert";
function died($error)
{
// your error code can go here
echo "<table><tr><img src=\"../../images/iclogo_small.jpg\" style=\"width: 300px\"/></tr><tr><br><strong>ERROR</strong><br />We are very sorry, but there were error(s) found with the form you submitted.</tr>";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go <a href=\"javascript:history.back()\">back</a> and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if
( !isset($_POST['staff_name']) ||
!isset($_POST['staff_department']) ||
!isset($_POST['problem']) ||
!isset($_POST['priority']) ||
!isset($_POST['gst_name']) ||
!isset($_POST['gst_room']) ||
!isset($_POST['incident']) ||
!isset($_POST['action']) ||
!isset($_POST['followup']) ||
!isset($_POST['gst_temp']) ||
!isset($_POST['case_status']) ||
!isset($_POST['gst_history'])
)
{
died('ERROR - There seems to be a problem with the form you submitted.');
}
$name = $_POST['staff_name']; // required
$department = $_POST['staff_department']; // required
$problem = $_POST['problem']; // required
$priority = $_POST['priority']; // not required
$gst_name = $_POST['gst_name']; // not required
$gst_room = $_POST['gst_room']; // not required
$incident = $_POST['incident']; // required
$action = $_POST['action']; // required
$followup = $_POST['followup']; // required
$gst_temp = $_POST['gst_temp']; // required
$case_status = $_POST['case_status']; // required
$gst_history = $_POST['gst_history']; // required
$time = date("F j, Y, g:i a");
$timestamp = strtotime($time);
$time_GMT11 = $timestamp + 39600; // 3600 sec. = 1 hour
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
$string_exp = "/^[A-Za-z .'-]+$/";
if (strlen($incident) < 2)
{
$error_message .= 'The Incident comments you entered do not appear to be valid.<br />';
}
if (strlen($action) < 2)
{
$error_message .= 'The Action Taken comments you entered do not appear to be valid.<br />';
}
if (strlen($error_message) > 0)
{
died($error_message);
}
$email_message = "Kindly be informed that a Guest Problem Alert has been raised. Form details below.\n\n";
function clean_string($string)
{
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
// EMAIL BODY - TEXT ONLY NO TABLE
// $email_message .= "Date: ".($time_GMT11)."\n";
// $email_message .= "Name: ".clean_string($name)."\n";
// $email_message .= "Department: ".clean_string($department)."\n";
// $email_message .= "Problem: ".clean_string($problem)."\n";
// $email_message .= "Priority: ".clean_string($priority)."\n"."\n";
// $email_message .= "Guest Name: ".clean_string($gst_name)."\n";
// $email_message .= "Guest Room: ".clean_string($gst_room)."\n";
// $email_message .= "Incident: ".clean_string($incident)."\n";
// $email_message .= "Action: ".clean_string($action)."\n";
// $email_message .= "Gst. Manner: ".clean_string($gst_temp)."\n";
// $email_message .= "Updated by: ".clean_string($gst_history)."\n";
// EMAIL BODY - TABLE
$email_message .= '
<html>
<head>
<title><strong>Guest Problem Alert<strong></title>
</head>
<body>
<p>A guest problem alert has been raised for your property, please see details below:</p>
<table>
<tr>
<th>Item</th><th>Score</th>
</tr>
<tr>
<td>Date & Time</td><td>'.clean_string($time_GMT11).'</td>
</tr>
<tr>
<td>Staff Name</td><td>'.clean_string($staff_name).'</td>
</tr>
<tr>
<td>Staff Department</td><td>'.clean_string($staff_department).'</td>
</tr>
<tr>
<td>Problem</td><td>'.clean_string($problem).'</td>
</tr>
<tr>
<td>Priority</td><td>'.clean_string($priority).'</td>
</tr>
<tr>
<td>Guest Name</td><td>'.clean_string($gst_name).'</td>
</tr>
<tr>
<td>Incident</td><td>'.clean_string($incident).'</td>
</tr>
<tr>
<td>Action</td><td>'.clean_string($action).'</td>
</tr>
<tr>
<td>Follow up</td><td>'.clean_string($followup).'</td>
</tr>
<tr>
<td>Guest Manner</td><td>'.clean_string($gst_temp).'</td>
</tr>
<tr>
<td>Case status</td><td>'.clean_string($case_status).'</td>
</tr>
<tr>
<td>Guest history update</td><td>'.clean_string($history).'</td>
</tr>
</table>
<p> All OPEN CASES must be follow up within 1 hour from now. Please consult with the Resort Assistant Manager on-duty for more details.<br /><br />Kind regards,<br />Patrick Maurer<br />Director of QCI<br />
</body>
</html>'
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($email_to, $email_subject, $email_message, $headers);
?>
<!-- place your own success html below -->
<font>Thank you for submitting the alert. Please call RAM to raise awareness as well.<br /><a href="javascript:history.back()">Go back</a></font>
<?php
}
die();
?>
</body>
</html>
Thanks a lot!
A2k