首页 > 解决方案 > 有人可以帮我修复我的联系表 PHP 代码吗?

问题描述

我在 PHP 中编写了一个联系表单,但出现错误,请您帮帮我吗?

php表单代码:

<form class="contact-form" action="submit.php" method="post"> 
              <div class="row">
                  <!--Name-->
                  <div class="col-md-6">
                      <input name="name" class="form-inp" type="text" placeholder="Name">
                  </div>
                  <!--Email-->
                  <div class="col-md-6">
                      <input name="email" class="form-inp" type="text" placeholder="Email">
                  </div>

                  <div class="col-md-12">
                      <!--Message-->
                      <textarea name="message" placeholder="How can I help you?" rows="7"></textarea>
                      <button name="submit" class="site-btn top_45 pull-right" type="submit">SUBMIT</button>
                  </div>
              </div>
          </form>

提交.php代码

<?php
if (isset($_POST['submit']){
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];

$mailTo = "info@xxxx.com";
$headers = "From: ".$email;
$txt = "You have received an email from ".$name.".\n\n".$message;

mail($mailTo, $email, $message);
header("Location: index.php?mailsend");
}

警告:未知:依赖系统的时区设置是不安全的。您需要使用 date.timezone 设置或 date_default_timezone_set() 函数。如果您使用了这些方法中的任何一种,但仍然收到此警告,您很可能拼错了时区标识符。我们现在选择时区“UTC”,但请设置 date.timezone 以选择您的时区。在 /home/brukitup/public_html/submit.php 第 2 行

解析错误:语法错误,第 2 行 /home/brukitup/public_html/submit.php 中的意外“{”

标签: phpemailsyntaxcontact-form

解决方案


解析错误:语法错误,第 2 行 /home/brukitup/public_html/submit.php 中的意外“{”

此错误是因为您缺少一个)in

if (isset($_POST['submit']){
                          ^^

至于您的其他警告,可能是由于 php 设置。在你的php.ini,设置这个

[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = <whatever timezone you want to use>

来源


推荐阅读