我的网站上有一个联系表格,但每当我点击提交时,我的电子邮件地址都没有收到任何内容,尽管它确实已经提交了。
HTML如下
<div id="contactform">
<form name="contact" method="post" action="PHP/send_form_email.php">
<ol>
<li><label>To </label>
<select name="emailaddress" id="emailaddress">
<option value="0"></option>
<option value="1">General Queries</option>
<option value="2">Webmaster Queries</option>
</select>
</li>
<li><label for="name">Name</label>
<input type="text" name="name" id="name"></input>
</li>
<li><label for="email">Email</label>
<input type="text" name="email" id="email"></input>
</li>
<li><label for="subject">Subject</label>
<input type="text" name="subject" id="subject"></input>
</li>
<li><label for="message">Message</label>
<textarea name="message" id="message" cols="45" rows="5"></textarea>
</li>
<li>
<input name="submit" type="submit" class="submit" id="submit" value="submit"></input>
</li>
</ol>
</form>
</div>
和PHP是
<?php
if(isset($_POST['email'])) {
$subject = $_REQUEST['subject'];
$emailaddress[1] = "email1@email.com";
$emailaddress[2] = "email2@email.com";
$contactnameindex = $_REQUEST['emailaddress'];
if ($contactnameindex == 0 || !isset($_REQUEST['emailaddress']))
die ("You did not choose a recipient. Please hit your browser back button and try again.");
else
$emailaddress = $emailaddress[$contactnameindex];
function died($error) {
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['name']) ||
!isset($_POST['email']) ||
!isset($_POST['subject']) ||
!isset($_POST['message'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$name = $_POST['name']; // required
$email = $_POST['email']; // required
$subject = $_POST['subject']; // required
$message = $_POST['message']; // required
$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$name)) {
$error_message .= 'The Name you entered does not appear to be valid.<br />';
}
if(strlen($message) < 2) {
$error_message .= 'The Message you entered does 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_message .= "name: ".clean_string($name)."\n";
$email_message .= "email: ".clean_string($email)."\n";
$email_message .= "subject: ".clean_string($subject)."\n";
$email_message .= "message: ".clean_string($message)."\n";
// 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);
?>
<!-- include your own success html here -->
Thank you for contacting us. We will be in touch with you very soon.
<?php
}
?>
显然我使用的电子邮件地址不是email1和email2,但是我已经检查了我使用的实际地址,它们都输入正确,有人可以帮忙吗?
答案 0 :(得分:0)
您$email_to
中的$email_subject
和mail()
未定义。
@mail($email_to, $email_subject, $email_message, $headers);
您的$email_to
可能应为$emailaddress
,基于
else $emailaddress = $emailaddress[$contactnameindex];
并且您的$email_subject
应该是clean_string($subject)
,基于
$subject = $_POST['subject'];
就像 -
@mail($emailaddress, clean_string($subject), $email_message, $headers);
答案 1 :(得分:0)
<?php
require_once "../common/lib.config.php";
require_once "../classess/class.GymFacility.php";
$Fobj= new GymFacility();
if(!$_GET['iDisplayStart'])
$StartIndex = 0;
else
$StartIndex = $_GET['iDisplayStart'];
if(!$_GET['iDisplayLength'])
$Limit = 10;
else
$Limit = $_GET['iDisplayLength'];
$result=$Fobj->GetAllGymFacility();
$row=array();
$link="";
for($i=0;$i<count($result);$i++)
{
$link=" <a id='addv' href=javascript:loadpg('gym_facility_v0/form_facility.php?id=".$result[$i]['refid']."')> <img src='../images/icons/middlenav/create.png' class='listimg' title='Edit '></a> <a id='addv' href=javascript:deleteitem('gym_facility_v0/delete_facility.php?id=".$result[$i]['refid']."')> <img src='../images/icons/middlenav/close.png' class='listimg' title='delete '></a> ";
$row[]=array($i+1,$result[$i]['gymfacilities'],$link);
}
$totacnt=count($result);
$fltcnt=count($result);
$output = array(
"sEcho" => intval($_GET['sEcho']),
"iTotalRecords" => $totacnt,
"iTotalDisplayRecords" =>$fltcnt ,
"aaData" => $row);
echo json_encode($output);
?>
<?php
require_once "../common/lib.config.php";
require_once "../classess/class.GymFacility.php";
$F=new GymFacility();
$id=$_GET['id'];
$IpArr['stat']='R';
$result=$F->DeleteGymFacility($IpArr,$id);
echo "gym_facility_v0/facility.php";
?>
<?php
require_once "../common/lib.config.php";
require_once "../classess/class.QueryBuilder.php";
class GymFacility extends QueryBuilder
{
public function GymFacility()
{
parent::__construct();
}
public function AddGymFacility($IpArr)
{
if(!$this->IsExist($IpArr['gymfacilities'],$refid=0)){
$this->SetTable('gymfacility');
$this->AddFlds($IpArr);
return $this->AddQuery();
}
return 'E';
}
public function EditGymFacility($IpArr, $Refid)
{
if(!$this->IsExist($IpArr['gymfacilities'],$Refid)){
$this->SetTable('gymfacility');
$this->AddFlds($IpArr);
$this->SetWhere("refid = '{$Refid}'");
$this->UpdQuery();
return $Refid;
}
return 'E';
}
public function UpdateGymFacility($IpArr, $Refid)
{
$this->SetTable('gymfacility');
$this->AddFlds($IpArr);
$this->SetWhere("refid = '{$Refid}'");
$this->UpdQuery();
return $Refid;
}
public function DeleteGymFacility($IpArr, $Refid)
{
$this->SetTable('gymfacility');
$this->AddFlds($IpArr);
$this->SetWhere("refid = '{$Refid}'");
$this->UpdQuery();
return $Refid;
}
public function GetAllGymFacility()
{
$this->SetTable('gymfacility');
$this->SetResultFlds("*");
$this->SetWhere("stat != 'R'");
$Res = $this->GetQuery();
return $Res;
}
public function GetGymFacilityById($refid)
{
$this->SetTable('gymfacility');
$this->SetResultFlds('*');
$this->SetWhere("stat != 'R' AND refid = '{$refid}' ");
$Res = $this->GetQuery();
return $Res;
}
public function IsExist($card_id, $refid)
{
$this->SetTable('gymfacility');
$this->SetResultFlds('*');
$this->SetWhere("gymfacilities = '{$card_id}' AND stat != 'R' AND refid !={$refid}");
$res=$this->GetQuery();
return count($res);
}
}
?>
CSSS
.title {
font-size: 20px;
color: #0C0;
}
body {
margin: 0;
padding: 0;
background: #FFF;
font-size: 12px;
color: #424242;
font-family: Arial, Helvetica, sans-serif;
line-height: 20px;
min-height: 100%;
position: relative;
rowElem {
clear: both;
border-top: 1px solid #e7e7e7;
padding: 10px 16px;
position: relative;
}
content {
padding-bottom: 80px;
overflow: hidden;
}
content {
padding-bottom: 80px;
overflow: hidden;
}
fieldset {
display: block;
-webkit-margin-start: 2px;
-webkit-margin-end: 2px;
-webkit-padding-before: 0.35em;
-webkit-padding-start: 0.75em;
-webkit-padding-end: 0.75em;
-webkit-padding-after: 0.625em;
border: 2px groove threedface;
border-image-source: initial;
border-image-slice: initial;
border-image-width: initial;
border-image-outset: initial;
border-image-repeat: initial;
min-width: -webkit-min-content;
}
title {
font-size: 20px;
color: #0C0;
}
greyishBtn:hover {
background-position: 0 -25px;
}
button {
font-size: 10px;
font-weight: bold;
text-transform: uppercase;
padding: 5px 14px 6px 14px;
cursor: pointer;
font-family: Arial, Helvetica, sans-serif;
line-height: 12px;
}
.submitForm {
float: right;
margin: 1px 27px 1px 16px;
}
.greyishBtn {
background: url(../images/ui/greyishBtn.png) repeat-x 0 0;
border: 1px solid #4f5a68;
color: #fff;
}
div {
display: block;
}