PHP 里面的脚本 HTML 提交表单

PHP Script inside HTML Submit form

我需要一些帮助。有人可以帮我处理这段代码吗?我需要此 HTML 中的 PHP 脚本,以便此预订正确发送电子邮件。在这种情况下,它会打开一个邮件程序,如 thunderbird、outlook、gmail 和任何类似的东西。我真的需要 PHP 在 HTML 里面。我使用的软件只能读取 HTML 和 JAVA。谢谢。

<!DOCTYPE HTML>
<html>
 <meta charset="UTF-8">
 <title>Hotel Booking Form</title>
<body>
 <form action="mailto:email name" method="GET">
 <fieldset>
  <legend>Personal Details:</legend>
  <label for="name">Username: </label><input type="text" name="username" id="name" required autofocus placeholder="Your username" pattern="[a-zA-Z]{3,}" title="Please enter more than three letters">
        <label for="email">Email: </label><input type="text" name="email" id="email" required placeholder="Your Email" pattern="[a-zA-Z]{3,}@[a-zA-Z]{3,}[.]{1}[a-zA-Z]{2,}" title="Please enter a valid email adress">
      <label for="phone">Phone:</label><input type="tel" name="phone" id="phone"  required placeholder="Please enter your phone number" pattern="[0-9]{4} [0-9] {3}" title="Please enter a phone number in this format: #### ### ###" >
        </fieldset>
        <br>
        <fieldset>
        <legend>Booking Detals:</legend>
        <label for="date"> Booking Date:</label> <input id="date" type="date" name="date" min="2013-12-02">
        <label for="numberOfGuests">Number Of Guests</label><input id="numberOfGuests" type="number" name="numberOfGuests" min="1" max="6">
        <p>Do you require meals?</p>
        <label for="yesMeals">Yes</label><input id="yesMeals" type="radio" name="meals" value="yesMeals">
       <label for="noMeals">No</label> <input id="noMeals" type="radio" name="meals" value="noMeals">
  <br>
        <input type="image" src="http://designshack.net/images/designs/submit-button_2.jpg">
                </fieldset>

</body>
</html>

您需要将表单的 action 更改为 PHP 脚本(需要与您的 HTML 中的名称相同)。并添加一个 submit 按钮(我在这里没看到?)。然后在脚本的顶部,将 $_GET 的值收集到一个字符串中,并使用 mail() 函数发送它。

<?php
if (isset($_GET['my_submit_button'])) {
    $body = "Email: $_GET[email]<br />\n";
    $body .="Phone: $_GET[phone]<br />\n";
    $body .="Number of Guests: $_GET[numberOfGuests]<br />\n";
    # etc.
    mail("youraddress@example.com", "Your Subject", $body);
} 
?>
<html> ... here you put your actual form - the code that you already have
<?php
}

以上内容过于简单化,但是,这个想法只是为了让您朝着正确的方向前进。

先改这个

<form action="mailto:email name" method="GET">

<form action="" method="GET">

并在文件末尾

<?php
if(isset($_GET)){
  $email = $_GET['email'];
  if (!filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
    echo("$email is a valid email address");
    # and use PHP's mail function to send email
  }
}

Reference to function

编辑

已编辑