我對於編寫php相當新穎,我有一個註冊表單,我希望將信息發送到我的電子郵件,但我認爲我在我的mail.php中缺少某些內容,因爲信息不會到達通過。用php發送表單
這是我的HTML5格式:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Register</title>
<link href="css/reset.css" rel="stylesheet" type="text/css">
<link href="css/register.css" rel="stylesheet" type="text/css">
</head>
<div id="container">
<section id="register">
<form action="mail.php" method="post" accept-charset="utf-8">
<h4>Your Jeep</h4>
<div class="form-field">
<fieldset>
<label>Year</label>
<input value="" placeholder="Year" type="text" name="year">
</fieldset>
</div>
<div class="form-field">
<fieldset>
<label>Color</label>
<input value="" placeholder="Color" type="text" name="color">
</fieldset>
</div>
<div class="form-field">
<fieldset>
<label>Class</label>
<input value="" placeholder="Stock, Modified, Highly Modified" type="text" name="class">
</fieldset>
</div>
<!--------------------
<div class="form-field">
<fieldset>
<label>Class</label>
<select class="form-field">
<option value="Select Class">Select Class</option>
<option value="Stock">Stock</option>
<option value="Modified">Modified</option>
<option value="Highly Modified">Highly Modified</option>
</select>
</fieldset>
</div>
------------------------->
<div class="form-field">
<fieldset>
<label>Last 4 digets of VIN</label>
<input value="" placeholder="Last 4 digets of VIN" type="text" name="vin">
</fieldset>
</div>
</form>
<form>
<h4>You</h4>
<div class="form-field">
<fieldset>
<label>Name</label>
<input value="" placeholder="Name" type="text" name="name">
</fieldset>
</div>
<div class="form-field">
<fieldset>
<label>Address</label>
<input value="" placeholder="Address" type="text" name="address">
</fieldset>
</div>
<div class="form-field">
<fieldset>
<label>City</label>
<input value="" placeholder="City" type="text" name="city">
</fieldset>
</div>
<div class="form-field">
<fieldset>
<label>State</label>
<input value="" placeholder="State" type="text" name="state">
</fieldset>
</div>
<div class="form-field">
<fieldset>
<label>Zip</label>
<input value="" placeholder="Zip" type="text" name="Zip">
</fieldset>
</div>
<div class="form-field">
<fieldset>
<label>Email</label>
<input value="" placeholder="Email" type="text" name="email">
</fieldset>
</div>
</form>
<form>
<div class="form-button">
<input type="submit" value="Send"><input type="reset" value="Clear">
</div>
</form>
</section>
</div>
<body>
</body>
</html>
,這是我mail.php:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Form</title>
</head>
<?php
$year= $_POST['year'];
$color= $_POST['color'];
$class= $_POST['class'];
$vin= $_POST['vin'];
$name= $_POST['name'];
$address= $_POST['address'];
$city= $_POST['city'];
$state= $_POST['state'];
$zip= $_POST['zip'];
$email= $_POST['email'];
$formcontent="From: $name \n From: $city";
$recipient = "[email protected]";
$subject = "JatB Registration";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!" . " -" . "<a href='index.html' style='text-decoration:none;color:#f15c25;'> Return Home</a>";
?>
<body>
</body>
</html>
我已經做了@alvaro建議的更改,並且信息可以發送。電子郵件地址的信息將是一個Hotmail的......但如果這是絕對必要的,我可以訪問一個郵件服務器。這就是爲什麼當點擊提交按鈕時彈出一個電子郵件窗口來發送信息? – mjadecole
你只需要一個窗體,所有的輸入和按鈕都應該在裏面。現在你有兩種不同的形式。然後你需要訪問郵件服務器來發送電子郵件。 – WAN
我把所有的領域和按鈕放在一個表格標籤,但現在當我點擊提交郵件新消息窗口出現在主題框中的信息。這是因爲沒有郵件服務器? – mjadecole