我已經創建了這個HTML表單和編碼的PHP,試圖在用戶填寫表單並單擊提交按鈕後將用戶信息發送到我的電子郵件。然而,因爲我點擊「提交」按鈕後只輸出了我的PHP代碼。請看看我的代碼,讓我知道我做錯了什麼。提前致謝。HTML表單沒有被提交。 PHP代碼不能正常工作
HTML代碼
<!DOCTYPE html>
<html>
<head>
<title>
learning jquery
</title>
<style>
textarea, input{
position:absolute; left:130px;
}
body{background-color:gray;}
h1{
text-align:center; margin-bottom:20px;
}
label{
position:absolute; left:145px;
}
#label1, #checkbox{position:relative;
top:125px;
}
#reset{position:absolute; top:500px;}
#submit{position:absolute; top:500px; left:200px;}
</style>
</head>
<body>
<h1>Please fill out the form below</h1>
<form action="form.php" method="post">
<p>E-mail Address: <input type="email" name="email"/></p>
<p>Name: <input type="text" name="name"/></p>
<p>Phone: <input type="tel" name="phone"/></p>
<p><p>
<input type="radio" name="budget" id="radio"/><label for="radio">$1,000</label><br>
<input type="radio" name="budget" id="radio1"/><label for="radio1">$1000 - $5000</label><br>
<span>Budget:</span><input type="radio" name="budget" id="radio2"/><label for="radio2">$5000 - $10000</label><br>
<input type="radio" name="budget" id="radio3"/><label for="radio3">$1,0000 - $25000</label><br>
<input type="radio" name="budget" id="radio4"/><label for="radio4">75,000 and up</label><br><br>
<span>How many people? </span><select id="select" name="traveler">
<option>Please Choose</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
<option>10</option>
<option>10+</option>
</select><br><br>
<span id="some_span">Comments:</span>
<textarea cols="40" rows="10" name="comments" id="textarea"></textarea><br>
<input type="checkbox" id="checkbox" name="newsletter"><label id="label1" for="checkbox">Subscribe to FREE online newspaper?</label>
<input type="reset" id="reset" value="Reset"/>
<input type="submit" id="submit" value="Send Email"/>
</form>
</body>
</html>
//PHP code
<?php
/*subject and email validates*/
$emailSubject = 'Having fun with PHP';
$webMaster = '[email protected]';
/* Gathering data variables */
$emailField = $_POST['email'];
$nameField = $_POST['name'];
$phoneField = $_POST['phone'];
$budgetField = $_POST['budget'];
$travelersField = $_POST['traveler'];
$commentsField = $_POST['comments'];
$newsletterField = $_POST['newsletter'];
$body = <<<EOD
<br><hr><br>
Email: $meail <br>
Name: $name <br>
Phone Number: $phone <br>
Budget: $budget <br>
Number of Travelers: $traveler <br>
Comments: $comments <br>
Newsletter: $newsletter <br>
EOD;
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail($webMaster, $emailSubject, $body, $headers);
/* Results rendered as HTML*/
$theResults = <<<EOD
<html>
<head>
<title>
PHP form
</title>
<style>
body{
background-color:gray;
}
</style>
</head>
<body>
<h1 style="text-align:center; margin-top:40px;">Thank you. Your Email was received. We will answer it soon.</h1>
</body>
</html>
EOD;
echo "theResults";
?>
爲什麼你在變量'$ theResults'上回顯'echo「theResults」;'當你有一個'HEREDOC'內容時。所以它應該是'echo $ theResults;'對嗎? –
在附註中,您所有的'
你有沒有在你的系統中安裝php? – krishna