Reputation: 11
I just started working for a new company and a previous employee developed their website using PHP. I'm not sure what he correctly/incorrectly. I know a good amount of HTML & CSS, can understand a very little bit about PHP, but not much. But I'm trying to learn on W3 Schools :)
I've got a contact form on my website, however whenever I click submit I do not receive anything to our e-mail address, although it does say it has been submitted.
Thank you in advance for you help!
Below is the code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>Anchor Technology | Services</title>
<?php include('includes/head.php'); ?>
<style type="text/css">#maintext .error h2 {color: red;</style>
</head>
<body>
<div id="maincontainer">
<?php include('includes/header.php'); ?>
<?php include('includes/navigation.php'); ?>
<div class="shadow">
<div id="maintext">
<h2>Help!</h2>
<!--Form options start here-->
<!--Small Form Here-->
<h2><strong>Existing Client Form</strong></h2>
<?php
error_reporting(E_ERROR | E_WARNING | E_PARSE);
$form_block = "
<p>Required fileds are marked with an asterick (*) </p>
<form action=\"$_SERVER[php_self]\"method=\"POST\">
<P>*Company Name:</p>
<input size=40 name=\"name\" value=\"$_POST[name]\"><br /> <br />
<p>*Contact Name:</p>
<input size=40 name=\"ctname\" value=\"$_POST[ctname]\"><br /><br />
<P>*Request Title:</p>
<input size=40 name=\"title\" value=\"$_POST[title]\"><br /><br />
<P>Description:</p>
<textarea cols=\"60\"rows=\"10\"name=\"description\">$_POST[description]</textarea><br /><br />
<P>Computer Name:</p>
<input size=20 name=\"cpname\" value=\"$_POST[cpname]\"><br /><br />
<p>User Name:</p>
<input size=40 name=\"uname\" value=\"$_POST[uname]\"><br /><br />
<P>Priority Level</p>
<select name=\"level\">
<option value=\"High\">High</option>
<option value=\"Medium\">Medium</option>
<option value-\"Low\" selected=\"default\">Low</option>
</select><br /><br />
<input type=\"hidden\" name=\"op\" value=\"ds\">
<input type=\"submit\" name=\"submit\" value=\"Submit\">
</form>";
if ($_POST[op] != "ds") {
//need to see form
echo "$form_block";
//check required fields
} else if ($_POST[op] == "ds") {
If (($_POST[name] == "") || ($_POST[ctname] == "") || ($_POST[title] == "")) {
$msg_err = "<div class=\"error\"<h2> <strong>Please fill in all required fields</strong></h2></div>";
$send = "no";
}
if ($send != "no") {
//it's ok to send
// create msg variable containing the message that will be sent to the email recipient
$msg .= "Company Name: $_POST[name]\n ";
// continue to concatenate the variable adding new pieces of information submitted
$msg .= "Company Name: $_POST[name]\n ";
$msg .= "Contact Name: $_POST[ctname]\n ";
$msg .= "Request Title: $_POST[title]\n ";
$msg .="Description:$_POST[description]\n";
$msg .= "Computer Name: $_POST[cpname]\n ";
$msg .= "User Name: $_POST[uname]\n ";
$msg .= "Priority Level: $_POST[level]\n ";
//Create variables to be used in the php Mail Function
$recipient = "[email protected]";
$subject = "Help request from $_POST[name]";
$mailheaders = "From: $_POST[ctname] \n";
$mailheaders .= "Reply-To: $_POST[ctname]";
//send mail form
//Use mail Function to Send
mail($recipient, $subject, $msg, $mailheaders);
// show confirmation message
// echo statements will be shown when script executes
echo "<p>Thank you, $_POST[name]!</p>";
echo "<p>Your message was sent!</p>";
echo "<a href=\"../index.php\">Return Home</a>";
} else if ($send == "no") {
//print error messages
echo "$msg_err";
echo "$form_block";
}
}
?>
<br /><br />
</div>
</div>
<div class="shadow">
<div id="footer">
<?php include('includes/footer.php'); ?>
</div>
</div>
</div>
</body>
</html>
Upvotes: 1
Views: 1328
Reputation: 11
Okay I found out the main issue from a friend that looked into this.
We are using IX Webhosting and have a Linux and a Microsoft server each hosting a few sites. The PHP site was being hosted on the Microsoft box which from what I was told is not setup to run PHP, but the Linux was.
Switched it over and no more problems.
Thanks all for your help!
Upvotes: 0
Reputation: 2133
First, narrow down the problem. Can you get any mail sent from PHP? Try a simple mail() test script to send a simple message.
If that works, then examine the mail($recipient, $subject, $msg, $mailheaders);
part of the code by echoing out or var_dump() the variables before the call to mail.
One problem is that PHP mail() returns boolean true or false based upon success, but the script as posted completely ignores this and just assumes it went ok. This isn't going to cause email not to send, but it WILL cause the script to report it was sent ok even if the mail() function flat-out told you it didn't work. Sadly this is never addressed in the documentation itself, and all the examples show mail without an attempt to check success.
Part of this is because mail() does not give useful error messages of any kind, so it usually just works or it doesn't - and if the function returns true it doesn't mean it really worked. For "mission critical" emails, do no use mail() alone to make sure you are getting important messages or capturing important data.
However, this is a start to finding out what is going wrong. First ensure proper PHP mail() functionality, then go from there.
Upvotes: 2