我刚开始为一家新公司工作,一位以前的员工使用 PHP 开发了他们的网站。我不确定他正确/错误的是什么。我知道大量的 HTML 和 CSS,对 PHP 有一点了解,但了解不多。但我正在尝试在 W3 学校学习 :)
我的网站上有一个联系表格,但是每当我单击提交时,我的电子邮件地址都没有收到任何内容,尽管它确实说它已提交。
提前感谢您的帮助!
下面是代码:
<!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 = "help@anchortechnology.com";
$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>