PHP/HTML联系人表单
我不确定为什么我的联系人表单不起作用,它使用html和php,但我一辈子都无法找出我做错了什么,因为它不起作用。我做了几周又几周的研究和实验,但仍然一无所获。如果有人能给我指出正确的方向,我将不胜感激。谢谢,我的代码在下面 HTMLPHP/HTML联系人表单,php,html,contact-form,Php,Html,Contact Form,我不确定为什么我的联系人表单不起作用,它使用html和php,但我一辈子都无法找出我做错了什么,因为它不起作用。我做了几周又几周的研究和实验,但仍然一无所获。如果有人能给我指出正确的方向,我将不胜感激。谢谢,我的代码在下面 HTML 你的名字: 电话: 电邮: 预算: 地点: 服务: 提货服务 重新密封 厕所水管 锅炉工程 外部管道 信息: PHP1联系人表单处理程序 <?php $errors = ''; $myemail = 'david@mil
你的名字:
电话:
电邮:
预算:
地点:
服务:
提货服务
重新密封
厕所水管
锅炉工程
外部管道
信息:
PHP1联系人表单处理程序
<?php
$errors = '';
$myemail = 'david@mildenhire.com';
if(empty($_POST['name']) ||
empty($_POST['telephone']) ||
empty($_POST['email']) ||
empty($_POST['budget']) ||
empty($_POST['location']) ||
empty($_POST['service']) ||
empty($_POST['message']))
{
$errors .= "\n Error: all fields are required";
}
$name = $_POST['name'];
$telephone = $_POST['telephone'];
$email_address = $_POST['email'];
$budget = $_POST['budget'];
$location = $_POST['location'];
$service= $_POST['service'];
$message = $_POST['message'];
if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
$email_address))
{
$errors .= "\n Error: Invalid email address";
}
if( empty($errors))
{
$to = $myemail;
$email_subject = "Free Quote: $name";
$email_body = "You have received a new free quote request. ".
" Here are the details:\n Name: $name \n Telephone: $telephone \n Email: $email_address \n Budget: $budget \n Location: $location \n Service: $service \n Message: \n $message";
$headers = "From: $email_address \n";
$headers .= "Reply-To: $email_address \n";
mail($to,$email_subject,$email_body,$headers);
header('Location: thankyou.html');
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Big Smile Free Quote Request</title>
</head>
<body>
<!-- This page is displayed only if there is some error -->
<?php
echo nl2br($errors);
?>
</body>
</html>
大微笑免费报价要求
PHP 2 contactformprocess.PHP
<?php
if(isset($_POST['Email_Address'])) {
include 'freecontactformsettings.php';
function died($error) {
echo "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();
}
if(!isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['comments'])
) {
died('Sorry, there appears to be a problem with your form submission.');
}
$full_name = $_POST['first_name']; // required
$email_from = $_POST['last_name']; // required
$telephone = $_POST['email']; // required
$comments = $_POST['telephone']; // required
$antispam = $_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)==0) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
if(strlen($first_name) < 2) {
$error_message .= 'Your First Name does not appear to be valid.<br />';
}
if(strlen($last_name) < 2) {
$error_message .= 'Your Last Name does not appear to be valid.<br />';
}
if(strlen($email) < 2) {
$error_message .= 'Your E-mail does not appear to be valid.<br />';
}
if(strlen($telephone) < 2) {
$error_message .= 'Your Telephone Number 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.\r\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:");
return str_replace($bad,"",$string);
}
$email_message .= "First Name: ".clean_string($first_name)."\r\n";
$email_message .= "Last Name: ".clean_string($last_name)."\r\n";
$email_message .= "E-Mail: ".clean_string($email)."\r\n";
$email_message .= "Telephone: ".clean_string($telephone)."\r\n";
$email_message .= "Message: ".clean_string($comments)."\r\n";
$headers = 'From: '.$email."\r\n".
'Reply-To: '.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
header("Location: $thankyou");
?>
<script>location.replace('<?php echo $thankyou;?>')</script>
<?php
}
die();
?>
位置。替换(“”)
我知道这是一个公平的位通读,但它不会花很长时间,因为它主要是PHP脚本。
我希望你们能帮助我你们这些优秀的人也许这只是SMTP配置的问题。 由于您没有收到任何错误,我假设函数
mail()
被正确调用,但是如果您的服务器没有正确配置为发送电子邮件,您将无法接收任何内容
我的建议是查看一下您的Web服务器配置(您可能正在使用WAMP或EasyHP之类的工具)。注意邮件头注入!垃圾邮件发送者可能会插入其他字段,如
Bcc
,并向其他人发送邮件。为什么你要公开你的消息是用PHP发送的,是用哪个版本?然后首先在您的邮件
语句之前删除该错误。您运行的是什么操作系统?如果是windows,则默认情况下windows没有邮件服务器。如果这是问题所在,请尝试phpMailer
。不,它是在支持php的服务器上发布的,smtp也可以,因为对于几个非常不同的电子邮件地址,它是相同的。
<?php
if(isset($_POST['Email_Address'])) {
include 'freecontactformsettings.php';
function died($error) {
echo "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();
}
if(!isset($_POST['first_name']) ||
!isset($_POST['last_name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['comments'])
) {
died('Sorry, there appears to be a problem with your form submission.');
}
$full_name = $_POST['first_name']; // required
$email_from = $_POST['last_name']; // required
$telephone = $_POST['email']; // required
$comments = $_POST['telephone']; // required
$antispam = $_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)==0) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
if(strlen($first_name) < 2) {
$error_message .= 'Your First Name does not appear to be valid.<br />';
}
if(strlen($last_name) < 2) {
$error_message .= 'Your Last Name does not appear to be valid.<br />';
}
if(strlen($email) < 2) {
$error_message .= 'Your E-mail does not appear to be valid.<br />';
}
if(strlen($telephone) < 2) {
$error_message .= 'Your Telephone Number 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.\r\n";
function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:");
return str_replace($bad,"",$string);
}
$email_message .= "First Name: ".clean_string($first_name)."\r\n";
$email_message .= "Last Name: ".clean_string($last_name)."\r\n";
$email_message .= "E-Mail: ".clean_string($email)."\r\n";
$email_message .= "Telephone: ".clean_string($telephone)."\r\n";
$email_message .= "Message: ".clean_string($comments)."\r\n";
$headers = 'From: '.$email."\r\n".
'Reply-To: '.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
header("Location: $thankyou");
?>
<script>location.replace('<?php echo $thankyou;?>')</script>
<?php
}
die();
?>