Простая контактная форма не отправляется

У меня есть простая контактная форма, которую не удается отправить, я новичок в PHP, поэтому, скорее всего, я что-то забыл или код неправильный. Я понимаю, что здесь много вопросов по той же теме, но я не уверен насчет своего кода.

Я получаю сообщение об ошибке: неопределенный индекс: отправить в \ mail.php в строке 31


HTML


<html>
<head>
<title>form</title>

</head>
<body>
<h2>Contact Form</h2>
<form id="form_id" name="form_name" action="mail.php" method="post">

<div>
<input type="text" name="name" id="name" placeholder="Name" required/>
</div>
<div>
<input type="email" name="email" id="email" placeholder="Email" required/>
</div>
<div>
<input type="number" name="tel" id="tel" placeholder="Phone" required/>
</div>

<textarea name="message" type="text" id="message" rows="5" cols="30" placeholder="Message" required></textarea>
</div>

<div>
<input type="submit" name="submit" value="submit" />
</div>

</form>
</body>
</html>

PHP


<?php

$to = 'test@gmail.com';
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$tel = $_POST['tel'];$body = <<<EMAIL

This is a message for your website.

Name: $name
Email: $email
Tel: $tel
Message: $message

EMAIL;

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'To: Bob <$to>, Bob <$to>' . "\r\n";
$headers .= 'From: Website <noreply@example.com>' . "\r\n";
$headers .= 'Cc: noreplt@example.com' . "\r\n";
$headers .= 'Bcc: noreply@example.com' . "\r\n";

if ($_POST['send']){
mail($to, $subject, $body, $header);
echo 'Message Sent.';
} else {

die('Failed to Send');
}?>

0

Решение

использование mail($to, $subject, $body, $headers);
здесь вы использовали заголовок $

4

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

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector