Хорошо, поэтому я искал все вокруг этого конкретного вопроса, но я не смог его найти, поэтому надеюсь, что это не повторение.PHP Форма электронной почты не отправляется
Таким образом, я создал форму контактов, используя мою страницу «/contacts.html», связанную с «html_form_send.php», расположенную на моем локальном хосте. После того, как пользователь нажимает «отправить» это сообщение появляется на следующей странице:..
«Мы очень сожалеем, но там были ошибки (s) нашли с формой отправленную вами Эти ошибки появляются ниже
Мы Извините, но возникнут проблемы с формой, которую вы подали.
Пожалуйста, вернитесь и исправьте эти ошибки. "
Это сообщение появляется, если вы заполните все поля или ни одно из полей, правильно или неправильно. Зачем?
<?php
if(isset($_POST['email'])) {
// CHANGE THE TWO LINES BELOW
$email_to = "[email protected]";
$email_subject = "Quantum1Connect Contact Request";
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']; // not required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // not required
$comments = $_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_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);
?>
<!-- place your own success html below -->
Thanks for contacting me! I will respond within 24 hours of receiving your message!
<?php
}
die();
?>
<div id="content">
<div class="content_item">
<h2>Contact Me!</h2>
<p>Whether you have constructive criticism, advise, questions, or a request, this is the place to do it! </p>
<form name="htmlform" method="post" action="http://localhost/html_form_send.php">
<div style="width:170px; float:left;"><p><label for="first_name">First Name *</label></p></div>
<div style="width:430px; float:right;"><p><input class="contact" type="text" name="first_name" value="" /></p></div>
<div style="width:170px; float:left;"><p><label for="last_name">Last Name </label></p></div>
<div style="width:430px; float:right;"><p><input class="contact" type="text" name="last_name" value="" /></p></div>
<div style="width:170px; float:left;"><p><label for="email">Email Address * </label></p></div>
<div style="width:430px; float:right;"><p><input class="contact" type="text" name="email" value="" /></p></div>
<div style="width:170px; float:left;"><p><label for="telephone">Phone Number </label></p></div>
<div style="width:430px; float:right;"><p><input class="contact" type="text" name="phone" value="" /></p></div>
<div style="width:170px; float:left;"><p><label for="comments">Message *</label></p></div>
<div style="width:430px; float:right;"><p><textarea class="contact textarea" rows="8" cols="50" name="message"></textarea></p></div>
<br style="clear:both;" />
<p style="padding: 10px 0 10px 0;">Please enter the answer to this simple math question (to prevent spam)</p>
<div style="width:170px; float:left;"><p>Maths Question: 9 + 3 = ?</p></div>
<div style="width:430px; float:right;">
<p><input type="text" name="user_answer" class="contact" /><input type="hidden" name="answer" value="4d76fe9775"/></p>
</div>
<div style="width:430px; float:right;">
<p style="padding-top: 15px"><form action="index.php"><input type="submit" value="Submit"></p>
</div>
</form>
</div><!--close content_item-->
Любая помощь будет очень признательна, большое вам спасибо!
Перейдите к ответу «raidenace'' ниже и внимательно прочитайте его. Это решит проблему. Если он все еще не работает, вам нужно будет начать проверку ошибок на вашем конце. Убедитесь, что у вас есть 'mail()', доступный с установленным, запущенным и правильно настроенным PHP. Спасибо raidenace [** accept **] (http://meta.stackexchange.com/a/5235/) [** ответ **] (http://stackoverflow.com/a/26262915/). –