【发布时间】:2012-02-17 15:14:37
【问题描述】:
在业余时间为当地的车身改装店做一些快速的网络开发工作;我正在尝试设置一个联系我们表单,除非我点击提交,它只返回 die();方法。我不太确定我做错了什么,因为我习惯于编程 Java,我只会得到错误方法。哈哈。如果有人能够帮助我,我的代码如下,问题区域在“联系”案例中。
<html>
<head>
<title>Darklite Tattoo & Piercing</title>
<link href="src/style.css" type="text/css" rel="stylesheet" /></link>
</head>
<body bgcolor="000048" />
<?php include("src/config.php"); ?>
<div align="center" /><img src="src/img/darklite_banner.jpg" /><br />
<div id="main" />
<?php echo("<a href=\"index.php\" />Home</a> · <a href=\"index.php?x=profiles\" />Profiles</a> · <a href=\"index.php?x=services\" />Services</a> · <a href=\"index.php?x=contact\" />Contact Us</a>"); ?>
<hr>
<?php
$x = $_GET['x'];
switch($x) {
case "profiles":
echo("Le profiles.");
break; case "services":
echo("Body piercings and tattoo's.");
break; case "contact":
if ($_POST["email"]<>'') {
$ToEmail = 'ihatejava@hotmail.com';
$EmailSubject = 'Site contact form ';
$mailheader = "From: ".$_POST["email"]."\r\n";
$mailheader .= "Reply-To: ".$_POST["email"]."\r\n";
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
$MESSAGE_BODY = "Name: ".$_POST["name"]."<br>";
$MESSAGE_BODY .= "Email: ".$_POST["email"]."<br>";
$MESSAGE_BODY .= "Comment: ".nl2br($_POST["comment"])."<br>";
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");
?>
Your message was sent
<?php
} else {
?>
<form action="index.php?x=contact" method="post">
<table width="400" border="0" cellspacing="2" cellpadding="0">
<tr>
<td width="29%" class="bodytext">Your name:</td>
<td width="71%"><input name="name" type="text" id="name" size="32"></td>
</tr>
<tr>
<td class="bodytext">Email address:</td>
<td><input name="email" type="text" id="email" size="32"></td>
</tr>
<tr>
<td class="bodytext">Comment:</td>
<td><textarea name="comment" cols="45" rows="6" id="comment" class="bodytext"></textarea></td>
</tr>
<tr>
<td class="bodytext"> </td>
<td align="left" valign="top"><input type="submit" name="Submit" value="Send"></td>
</tr>
</table>
</form>
<?php
};
break; default:
echo("Welcome to Darklite Tattoo & Piercing!");
break;
}
?>
</div>
</div>
</body>
</html>
【问题讨论】:
-
你遇到了什么错误?
-
没有错误,直接进入死机("Failure");方法。
-
检查您的 SMTP 服务器是否正在运行
-
我添加了一个“print(error_get_last());”到我的代码;没有输出。