我需要一些帮助。有人可以帮我这个代码。我需要在此HTML中使用PHP脚本才能正确发送电子邮件。因此在这种情况下它会打开像thunderbird,outlook,gmail这样的邮件程序。我真的需要PHP是INSIDE的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>
&#13;
答案 0 :(得分:1)
您需要将表单的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
}
以上是过于简单的,但是,这个想法只是为了让你朝着正确的方向前进。
答案 1 :(得分:1)
首先改变这个
<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
}
}
修改强>
编辑