所以我刚刚将所有内容都放在我的网站上,我已将所有内容设置为我认为正确的...但由于某种原因,在表单提交后,它只是加载'send_form_email.php'页面,给出了网站访问者一个空白页面..我似乎也没有收到发送到我的收件箱的电子邮件..我无法弄清楚我哪里出错了..我猜的是HTML?
以下是表单的HTML代码,如果您需要查看整个网页html,请告诉我:
<!-- form -->
<form name="contactform" id="contactform" method="post" action="send_form_email.php">
<fieldset>
<legend class="lined">Pre-Register for free!</legend>
<label for="pname">Name</label>
<input name="pname" id="pname" value="" type="text">
<label for="pemail">Email</label>
<input name="pemail" id="pemail" value="" type="text">
<label for="company">Business Name</label>
<input name="company" id="company" value="" type="text">
<label for="comment">Where do you offer your services?</label>
<textarea name="comments" id="comments"></textarea>
</fieldset>
<input type="submit" value="Submit">
</form><!-- /form -->
这是PHP代码(文件名send_form_email.php);
<?php
if(isset($_POST['pemail'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = 'info@whichpt.com';
$email_subject = 'Pre-Registration Submission';
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['pname']) ||
!isset($_POST['pemail']) ||
!isset($_POST['company']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$pname = $_POST['pname']; // required
$pemail = $_POST['pemail']; // required
$company = $_POST['company']; // not required
$comments = $_POST['comments']; // required
$error_message = '';
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$pemail)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = '/^[A-Za-z .'-]+$/';
if(!preg_match($string_exp,$pname)) {
$error_message .= 'The Name you entered does not appear to be valid.<br />';
}
if(strlen($comments) < 2) {
$error_message .= 'The location of services information 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_message .= 'Name: '.clean_string($pname).'\n';
$email_message .= 'Email: '.clean_string($pemail).'\n';
$email_message .= 'Business: '.clean_string($company).'\n';
$email_message .= 'Comments: '.clean_string($comments).'\n';
// create email headers
$headers = 'From: '.$pemail.'\r\n'.
'Reply-To: '.$pemail.'\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
}
?>
答案 0 :(得分:2)
我认为你的意思是$_POST['pemail']
if(isset($_POST['pemail'])) { ... }
代替。
答案 1 :(得分:-1)
// create email headers
$headers = 'From: '.$pemail."\r\n".
'Reply-To: '.$pemail."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
你正在混合串联..例如:
$headers = 'From: '.$pemail."\r\n".
应为$headers = 'From: '.$pemail.'\r\n'.
至少可以拍摄以便于调试。但请参阅Alexander的答案,以确保您可以先评估if语句。