我有一个包含3个输入字段的表单,以下字段未按预期工作,发布数据未发布,其余两个输入字段正常工作
<form id="main-contact-form" class="contact-form" name="contact-form" method="post" action="sendemail.php?m=std">
<div class="row contact-wrap">
<div class="status alert alert-success" style="display: none"></div>
<form id="main-contact-form" class="contact-form" name="contact-form" method="post" action="sendemail.php?m=std">
<div class="col-sm-10 col-sm-offset-1">
<div class="form-group">
<label>Name *</label>
<input type="text" name="name" class="form-control" required="required">
</div>
<div class="form-group">
<label>Email *</label>
<input type="email" name="email" class="form-control" required="required">
</div>
</div>
<div class="col-sm-5 col-sm-offset-1">
<h4>Doing graduation</h4>
<div class="form-group">
<label>Name of college</label>
<input type="text" name="dngclgname" class="form-control" >
</div>
<div class="form-group">
<label>Place </label>
<input type="text" name="dngclgplace" class="form-control">
</div>
<div class="form-group">
<label>Completing in</label>
<input type="text" name="dngcomp" class="form-control">
</div>
</div>
<div class="col-sm-5 col-sm-offset-1">
<h4>Completed Graduation</h4>
<div class="form-group">
<label>Name of college</label>
<input type="text" name="clgname" class="form-control" >
</div>
<div class="form-group">
<label>Place </label>
<input type="text" name="clgplace" class="form-control">
</div>
<div class="form-group">
<label>Year of completion</label>
<input type="text" name="comp" class="form-control">
</div>
</div>
<div class="col-sm-5 col-sm-offset-1">
<h4>Post Graduation</h4>
<div class="form-group">
<label>Name of college</label>
<input type="text" name="pgclgname" class="form-control" >
</div>
<div class="form-group">
<label>Place </label>
<input type="text" name="pgclgplace" class="form-control">
</div>
<div class="form-group">
<label>Year of completion</label>
<input type="text" name="pgcomp" class="form-control">
</div>
</div>
<div class="col-sm-5 col-sm-offset-1">
<h4>Working</h4>
<div class="form-group">
<label>Name of Company</label>
<input type="text" name="companyname" class="form-control" >
</div>
<div class="form-group">
<label>Place </label>
<input type="text" name="companyplace" class="form-control">
</div>
<div class="form-group">
<label>Working since</label>
<input type="text" name="companywrk" class="form-control">
</div>
<div class="form-group">
<label>Total no of years of experience</label>
<input type="text" name="companyexp" class="form-control">
</div>
</div>
<div class="col-sm-10 col-sm-offset-1">
<div class="form-group">
<label>Subject *</label>
<input type="text" name="subject" class="form-control" required="required">
</div>
<div class="form-group">
<label>Your Message/ Query/ Information required *</label>
<textarea name="message" id="message" required="required" class="form-control" rows="8"></textarea>
</div>
<div class="form-group">
<button type="submit" name="submit" class="btn btn-primary btn-lg" required="required">Submit Message</button>
</div>
</div>
</form>
</div><!--/.row-->
这是我的PHP代码的一部分
header('Content-type: application/json');
$status = array(
'type'=>'success',
'message'=>'Thank you for contacting us. As early as possible we will contact you '
);
// some code here (if condition, check if user has input other form , if user input this form everything is fine)
elseif($m == 'std'){
$name = trim(stripslashes($_POST['name']));
$email = trim(stripslashes($_POST['email']));
$subject = trim(stripslashes($_POST['subject']));
$message = trim(stripslashes($_POST['message']));
$dngclgname = trim(stripslashes($_POST['dngclgname']));
$dngclgplace = trim(stripslashes($_POST['dngclgplace']));
$dngcomp = trim(stripslashes($_POST['dngcomp']));
$clgname = trim(stripslashes($_POST['clgname']));
$clgplace = trim(stripslashes($_POST['clgplace']));
$comp = trim(stripslashes($_POST['comp']));
$pgclgname = trim(stripslashes($_POST['pgclgname']));
$pgclgplace = trim(stripslashes($_POST['pgclgplace']));
$pgcomp = trim(stripslashes($_POST['pgcomp']));
$companyname = trim(stripslashes($_POST['companyname']));
$companyplace = trim(stripslashes($_POST['companyplace']));
$companywrk = trim(stripslashes($_POST['companywrk']));
$companyexp = trim(stripslashes($_POST['companyexp']));
$email_from = $email;
$email_to = 'my email address';//replace with your email
$body = 'Name: ' . $name . "\n\n" . 'Email: ' . $email . "\n\n" . 'graduating college name: ' . $dngclgname . "\n\n" . 'graduating college Place: ' . $dngclgplace . "\n\n" . 'graduation completion year: ' . $dngcomp . "\n\n" . ' graduated College name: ' . $clgname . "\n\n" . ' graduated College Place: ' . $clgplace . "\n\n" . ' Graduated Year: ' . $comp . "\n\n" . 'Post Graduation College name: ' . $pgclgname . "\n\n" . 'Post Graduation College Place: ' . $pgclgplace . "\n\n" . 'Post Graduation Completion/completed year: ' . $pgcomp . "\n\n" . 'Company name: ' . $companyname . "\n\n" . ' Company place: ' . $companyplace . "\n\n" . 'Working since : ' . $companywrk . "\n\n" . 'Total no of years of experience : ' . $companyexp . "\n\n" . 'Subject: ' . $subject . "\n\n" . 'Message: ' . $message;
$success = @mail($email_to, $subject, $body, 'From: <'.$email_from.'>');
echo json_encode($status);
die;
}
当我点击提交时,我正在重定向到正确的网址,甚至邮件都会到达我的地址,但邮件中的所有用户输入文件都是空的,即使邮件中的地址也是空的,
答案 0 :(得分:0)
您应该使用var_dump($ _ POST)调试代码。
您将看到所有输入值是否有效。
当我尝试使用您的代码时,一切运行良好。