我是网络开发的新手,但我现在正在玩我的想法,我想创建一个页面,允许登录用户报告问题,然后发送到任何电子邮件中该用户的电子邮件字段。问题是,当我点击提交按钮时,我只是被带到一个白页,但是看起来任何一个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部分没有在al上显示
// 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
}
?>
答案 0 :(得分:1)
看起来你有很多输入没有任何name
参数,PHP用来填充$_GET
/ $_POST
<input id="fullname" type="text" maxlength="64">
应该是这样的:
<input id="fullname" name="fullname" type="text" maxlength="64">
^^^^^^^^^^^^^^^
Theres可能会在您的脚本中出现更多错误,但添加此错误可能会对您有所帮助
您还提到正在填充$log_id
和$log_username
但是checkuserlogin.php
在哪里被调用?它是在db_conx.php
中调用的,否则就是你的问题。您可能希望打开错误消息以接收消息。
答案 1 :(得分:0)
添加名称参数,如类所述,也可以更改
<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"); ?>
答案 2 :(得分:0)
好的,所以我已经让它出现了一件事,问题是我在我的problem_form_email.php中没有包含checkuserlogin.php,因此我的sql语句无法执行。但现在我只是不断收到下面显示的错误。我没办法让它们停下来,还有其他任何帮助?