HTML — PHP контактная форма электронной почты

Я искал здесь и в Google, как сделать контактную форму для работы, и я не смог.

Я скачал «контактную форму php», но я не знаю, как заставить это работать. Я знаю, что было много заданных вопросов по этому поводу, но, пожалуйста, помогите мне. Я застрял здесь: /

Это HTML-код:

<form action="form-to-email.php" name="myemailform" method="post">
<div>
<span>Name</span>
<input type="text" name="name" value="" placeholder="Your Name">
</div>

<div>
<span>Email</span>
<input type="email" name="email" autocapitalize="off" autocorrect="off" value="" placeholder="example@domain.com">
</div>

<div><textarea name="message" placeholder="Message"></textarea></div>

<div class="code">
<button><input type="submit" name='submit' value="Send"></button>
</div>
<i class="clear" style="display: block"></i>
</div>
</form>

А вот «бесплатный код формы PHP», который я скачал с сайта:

<?php
if(!isset($_POST['submit']))
{
//This page should not be accessed directly. Need to submit the form.
echo "error; you need to submit the form!";
}
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];

//Validate first
if(empty($name)||empty($visitor_email))
{
echo "Name and email are mandatory!";
exit;
}

if(IsInjected($visitor_email))
{
echo "Bad email value!";
exit;
}

$email_from = 'myEmail@domain.com';//<== update the email address
$email_subject = "New Form submission";
$email_body = "You have received a new message from the user $name.\n".
"Here is the message:\n $message".

$to = "myEmail@domain.com";//<== update the email address
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
//Send the email!
mail($to,$email_subject,$email_body,$headers);
//done. redirect to thank-you page.
header('Location: thank-you.html');// Function to validate against any email injection attempts
function IsInjected($str)
{
$injections = array('(\n+)',
'(\r+)',
'(\t+)',
'(%0A+)',
'(%0D+)',
'(%08+)',
'(%09+)'
);
$inject = join('|', $injections);
$inject = "/$inject/i";
if(preg_match($inject,$str))
{
return true;
}
else
{
return false;
}
}

?>

Нужно ли что-то делать в MySQL или делать что-то еще?
Спасибо за помощь!

0

Решение

Вот "Here is the message:\n $message". <= увидеть точку? Это должна быть точка с запятой.

Вот почему код OP не работает.

добавлять Отчет об ошибках в начало вашего файла (ов), который поможет найти ошибки, которые будут иметь.

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

// rest of your code

Примечание: Отчеты об ошибках должны выполняться только на стадии подготовки, а не на производстве.

1

Другие решения

все выглядит правильно, просто добавьте выход после перенаправления.

header('Location: thank-you.html');
exit;
1