1
我一直在試圖創建一個表單,將收集用戶的姓名,電子郵件和問題,但我是如此新的PHP,我一直在努力與它。PHP的電子郵件驗證和從HTML表格檢索
目標是收集信息,當他們按下提交時,他們的電子郵件地址應該發送到我的電子郵件,我希望它被驗證,它是一個真正的電子郵件地址。
HTML代碼:
<form method="post" action="process.php">
<fieldset>
<legend>Personal Information</legend>
<p><label for="name">Name:</label>
<input type="text" name="name" id="name" maxlength="50" autofocus required /></p>
<p><label for="recipient">Email Address:</label>
<input id="recipient" name="recipient" type="text" name="recipient" required></p>
</fieldset>
<fieldset>
<legend>Tours Interested In:</legend>
<p><label for="question">Questions/Comments:</label>
<textarea id="question" name="question" cols="50" rows="3" placeholder="type your comments here" required></textarea>
</fieldset>
<p class="centralize"><input type="submit" onclick="send()" value="Submit Only" /></p>
<p class="centralize"><input type="reset" value="Clear Form"></p>
<p id="data_return"></p>
</form>
PHP代碼:
<?php
header("Content-type: text/html");
$name=$_POST["name"];
$question=$_POST["question"];
$email =$_POST["email"];
$subject = "You have a USER INQUIRY:";
$to = '[email protected]';
if(!$_POST['name']){
$errName = 'Please enter your name';
}
echo "<p>Thank you, $name . Your Email has been Sent, and we will get back to you within 48 hours.</p>";
//Build email (to myself)
mail($to, $name, $subject, $question, $email);
查看郵件功能在手冊中接受的參數 – 2016-04-24 22:16:46