我已经研究了这个问题,但是我认为我找不到答案,因为我猜我个人的代码有问题。我尝试过各种尝试,尝试使我的PHP联系人表单提交并给我发送电子邮件,但是即使它已上传到服务器,它也无济于事。单击“提交”后,它仅显示一个空白页,而我输入到代码中的电子邮件地址根本没有电子邮件。我不知道自己缺少什么,因为我无法在任何地方找到解决问题的答案。
我确实注意到的一件事是,我的HTML中有一些与PHP中指定的必填字段不同的字段。但是,我不知道这有什么区别,因为我没有收到这些字段的任何错误消息或其他任何消息。如果您需要任何其他详细信息,请告诉我。感谢您的帮助。
的HTML
<form id="form_884913" method="post" action="send_form_email.php" class="appnitro">
这是我所有字段的所在,因此我省略了它,因为脚本很大。如果您需要任何帮助,请告诉我
HTML的其余部分
<input type="hidden" name="form_id" value="884913" />
<input id="saveForm" class="button_text" type="submit" name="submit" value="Submit" />
<input type="reset" value="Reset">
</form>
的PHP
<?php
if(isset($_POST['email'])) {
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "[email protected]";
$email_subject = "Contact";
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['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['comments'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_POST['first_name']; // required
$last_name = $_POST['last_name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // 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,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
if(!preg_match($string_exp,$last_name)) {
$error_message .= 'The Last Name you entered does not appear to be valid.<br />';
}
if(strlen($comments) < 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_message .= "First Name: ".clean_string($first_name)."\n";
$email_message .= "Last Name: ".clean_string($last_name)."\n";
$email_message .= "Email: ".clean_string($email_from)."\n";
$email_message .= "Telephone: ".clean_string($telephone)."\n";
$email_message .= "Comments: ".clean_string($comments)."\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 me! I will be in touch with you very soon.
<?php
}
?>
如果要对HTML&PHP中的表单使用$_POST
(与$_GET
方法相同),则必须这样命名字段:
<input type="text" name="MyfieldName" value="1">
只有这样你才能打电话给你 $_POST['MyfieldName']
现在,如果您愿意echo $_POST['MyfieldName'];
,它将返回1
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句