Я не уверен, почему моя контактная форма не работает, она использует html и php, но я не могу на всю жизнь работать над тем, что я сделал неправильно, чтобы она не работала. Я провел недели и недели исследований и экспериментов и все еще ничего. Я был бы очень признателен, если бы кто-нибудь мог указать мне в правильном направлении. Спасибо, мой код нижеPHP/HTML Форма обратной связи
HTML
<form method="POST" name="contactform" action="contact-form-handler.php">
<p align="center">
<label for='name'><FONT color="#FFFFFF" SIZE=2>YOUR NAME:</FONT></label>
<font color="#FFFFFF">
<input name="name" type="text">
</font></p>
<p align="center">
<font color="#FFFFFF">
<label for='telephone'><FONT SIZE=2>TELEPHONE:</FONT></label>
<input name="telephone" type="text">
</font></p>
<p align="center">
<font color="#FFFFFF">
<label for='email'><FONT SIZE=2>EMAIL:</FONT></label>
<input name="email" type="text">
<br>
</font></p>
<p align="center">
<font color="#FFFFFF">
<label for='budget'><FONT SIZE=2>BUDGET:</FONT></label>
<input name="budget" type="text" id="finish">
<br>
</font></p>
<p align="center">
<font color="#FFFFFF">
<label for='location'><FONT SIZE=2>LOCATION:</FONT></label>
<input name="location" type="text" id="location">
<br>
</font></p>
<p align="center">
<font color="#FFFFFF">
<label for='service'><FONT SIZE=2>SERVICE:</FONT></label>
<select id="service" name="service">
<option value="000">Pick Service</option>
<option>Resealing</option>
<option>Toilet Plumbing</option>
<option>Boiler Work</option>
<option>Exterior Plumbing</option>
</select>
</font></p>
<p align="center">
<font color="#FFFFFF">
<label for='message'><FONT SIZE=2>INFO:</FONT></label>
<textarea name="message"></textarea>
</font></p>
<div align="center">
<font color="#FFFFFF">
<input type="submit" value="SUBMIT">
</font></div>
</form>
PHP1 контакт форм-обработчик
<?php
$errors = '';
$myemail = '[email protected]';
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._%-][email protected][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 Script. Надеюсь, вы можете мне помочь вам, прекрасные люди
Остерегайтесь встраивания заголовка письма! Спамер может вставить другие поля, такие как «Bcc», и отправить почту другим пользователям. И почему вы показываете, что ваше сообщение отправлено с помощью PHP и с какой версией? И сначала удалите эту ошибку, подавляющую '@' перед вашим заявлением 'mail'. –
В какой ОС вы работаете? Если его окна, окна не имеют почтового сервера по умолчанию. Если это проблема, попробуйте 'phpMailer'. – RiggsFolly