doujiling4377 2014-12-08 10:45
浏览 12
已采纳

简单的联系表单无法发送

I have a simple contact form that is failing to send, I'm new to PHP so it's most likely I have forgotten something or the code is wrong. I understand that there are many questions on here around the same subject but I'm unsure about my code.

I'm getting the error message: Undefined index: send in \mail.php on line 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' . "
";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "
";

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

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

    die('Failed to Send');
} 


?>
  • 写回答

1条回答 默认 最新

  • dongyan1491 2014-12-08 10:49
    关注

    use mail($to, $subject, $body, $headers); here you used $header

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 易康econgnition精度验证
  • ¥15 线程问题判断多次进入
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致