我对web开发非常陌生,但我现在有一个想法,我想做一个页面,允许登录的用户报告问题,并将其发送到该用户的电子邮件字段中的任何电子邮件。问题是,当我点击提交按钮时,我只会被带到一个白色的页面,但是似乎没有任何一个php在工作。我在我的页面顶部和页面底部做了一个include_once,它们出现了,所以看起来PHP正在运行,但我什么也得不到。有没有人可以看看这个,并建议为什么它可能不起作用?
谢谢。
这是我的表单所在的页面,看起来一切都在进行中。
<?php
include_once("php_includes/problem_form_email.php"); ?>
<form action="problem_form_email.php" method="post" name="reportform" id="reportform">
<div>Full Name: </div>
<input id="fullname" type="text" maxlength="64">
<div>Your Email address:</div>
<input id="tenantemail" type="text" maxlength="88">
<div>Your Phone number:</div>
<input id="phonenumber" type="text" maxlength="64">
<div>House Number or Name:</div>
<input id="housenumber" type="text" maxlength="64">
<div>First Line of address:</div>
<input id="streetname" type="text" maxlength="64">
<div>City:</div>
<input id="city" type="text" maxlength="64">
<div>Your Postcode:</div>
<input id="postcode" type="text" maxlength="14">
<div>Type of Problem:</div>
<select id="typeofproblem">
<option value="">TYPE OF PROBLEM</option>
<option value="Water">Water</option>
<option value="Decor">Decor(Paintwork, wallpaper etc.)</option>
<option value="Heating">Heating</option>
<option value="Windows">Windows</option>
<option value="Flooring">Flooring</option>
<option value="Kitchen">Kitchen</option>
<option value="Furniture">Furniture</option>
<option value="Roofing">Roofing</option>
</select>
<div>Describe your problem (Please be detailed):</div>
<TEXTAREA style="resize:none; width:300px;" name="probdesc" ROWS=8 COLS=64 onfocus="emptyElement('status')"></textarea>
<div>How urgent is this problem?:<br> Urgency is to help us filter the most in need cases, please don't abuse it.</div>
<select id="urgency" onfocus="emptyElement('status')">
<option value="">Choose an option</option>
<option value="Very Low">Very Low</option>
<option value="Low">Low</option>
<option value="Medium">Medium</option>
<option value="High">High</option>
<option value="Very High">Very High</option>
</select>
<div>
</div>
<br /><br />
<input type='submit' value="Report Problem">
</form>然后,所有变量都应该转到我的另一个页面,该页面将向用户发送一封电子邮件,然后显示某种成功的HTML。这就是我想我做错了什么的地方。看看..。
我使用了一个模板表单提交页面,并对其进行了更改,模板表单可以在这里找到。http://www.freecontactform.com/email_form.php
我只想澄清一下,这个php页面的HTML部分不会显示在
// EDIT THE 2 LINES BELOW AS REQUIRED
include_once("php_includes/db_conx.php");
$sql = "SELECT email FROM users WHERE id='$log_id' AND username='$log_username'LIMIT 1";
$email_to = mysqli_query($db_conx, $sql);
echo "$email_to";
$email_subject = "MOUSE ACCOUNT - A Tenant has reported a problem";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if(!isset($_POST['fullname']) ||
!isset($_POST['tenantemail']) ||
!isset($_POST['phonenumber']) ||
!isset($_POST['housenumber']) ||
!isset($_POST['streetname']) ||
!isset($_POST['city']) ||
!isset($_POST['postcode']) ||
!isset($_POST['typeofproblem']) ||
!isset($_POST['probdesc']) ||
!isset($_POST['urgency'] )) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$fullname = preg_replace('#[^a-z0-9."@; ]#i', '', $_POST['fullname']);
$tenantemail = mysqli_real_escape_string($db_conx, $_POST['tenantemail']);
$phonenumber = preg_replace('#[0-9 ]#i', '', $_POST['phonenumber']);
$housenumber = preg_replace('#[^a-z0-9 ]#i', '', $_POST['housenumber']);
$streetname = preg_replace('#[^a-z0-9 ]', '', $_POST['streetname']);
$city = preg_replace('#[^a-z ]', '', $_POST['city']);
$postcode = preg_replace('#[^a-z0-9 ]', '', $_POST['postcode']);
$typeofproblem = preg_replace('#[^a-z0-9 ]', '', $_POST['typeofproblem']);
$probdesc = preg_replace('#[^a-z0-9."@; ]', '', $_POST['probdesc']);
$urgency = preg_replace('#[^a-z0-9 ]#i', '', $_POST['urgency']);
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$tenantemail)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$fullname)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$phonenumber)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
if(strlen($probdesc) < 2) {
$error_message .= 'The Comments you entered do not appear to be valid.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\n\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}
$email_from = "maintenance@mouseaccount.com";
$email_message = '<!DOCTYPE html><html><head><meta charset="UTF-8"><title>Maintenance Request</title></head><body style="margin:0px; font-family:Tahoma, Geneva, sans-serif;"><div style="padding:10px; background:#333; font-size:24px; color:#CCC;"><a href="http://www.mouseaccount.com"><img src="http://www.mouseaccount.com/images/logo.png" width="36" height="30" alt="Mouse Account" style="border:none; float:left;"></a>A tenant reported a problem!</div><div style="padding:24px; font-size:17px;">Hello,<br /><br />A tenant has reported a problem at their property, please view below to see the details of the report so you can contact them.
<br /><br />Name: <b>'.$fullname.'</b><br /><br />
<br /><br />Tenants Contact Email: <b>'.$tenantemail.'</b><br /><br />
<br /><br />Tenants Phone Number: <b>'.$phonenumber.'</b><br /><br />
<br /><br />House Number: <b>'.$housenumber.'</b><br /><br />
<br /><br />Street Name: <b>'.$streetname.'</b><br /><br />
<br /><br />City: <b>'.$city.'</b><br /><br />
<br /><br />Postcode: <b>'.$postcode.'</b><br /><br />
<br /><br />Category of Problem: <b>'.$typeofproblem.'</b><br /><br />
<br /><br />Description of their problem <br /><br />:'.$probdesc.'<br /><br />
<br /><br />Urgency Indicated by tenant: <b>'.$urgency.'</b><br /><br />
Tenants Contact Email:<br />* E-mail Address: <b>'.$e.'</b></div></body></html>';
$headers = "From: $from\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
mail($to, $subject, $message, $headers);
echo "signup_success";
exit();
// 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);
?>
<html>
<head>
<meta charset="UTF-8">
<title>Mouse Account</title>
<link rel="icon" href="favicon.ico" type="image/x-icon">
<link rel="stylesheet" href="style/style.css">
<script src="root/js/main.js"></script>
</head>
<body>
<?php include_once("template_pageTop.php");?>
<div id="maincontent">
<div id="pageMiddle">
<div id="img1"><img src="images/welcome_toMA.png" id="img1"></img></div></div></div>
<?php include_once("template_pageBottom.php");?>
</body>
</html>
<?php
}
?>发布于 2014-02-03 17:19:00
看起来您有很多没有任何name参数的输入,PHP使用这些参数来填充$_GET/$_POST
<input id="fullname" type="text" maxlength="64">它应该如下所示:
<input id="fullname" name="fullname" type="text" maxlength="64">
^^^^^^^^^^^^^^^您的脚本中可能会有更多错误,但添加此代码应该会对您有所帮助
您还提到正在填充$log_id和$log_username,但是在哪里调用checkuserlogin.php呢?它是否在db_conx.php中被调用,否则就有问题了。您可能希望打开错误消息以接收消息。
发布于 2014-02-03 17:41:44
添加名称参数,如Class said和change
<input type='submit' value="Report Problem">至
<input type="submit" value="Report Problem">也删除
include_once("php_includes/problem_form_email.php");你不需要这个,否则你不会关闭php标签
<?php
include_once("php_includes/problem_form_email.php");将其更改为
<?php
include_once("php_includes/problem_form_email.php"); ?>发布于 2014-02-03 18:11:12
好的,我让它显示了一件事,问题是我没有在我的problem_form_email.php中包含checkuserlogin.php,所以我的sql语句不能执行。但现在我只是不断得到下面显示的错误。我没办法让他们停下来,有什么额外的帮助吗?
https://stackoverflow.com/questions/21523415
复制相似问题