PHP电子邮件验证和从HTML表单检索
我一直在尝试创建一个表单来收集用户名、电子邮件和问题,但我对PHP太陌生了,所以我一直在努力使用它 目标是收集信息,当他们按submit时,他们的电子邮件地址应该被发送到我的电子邮件中,我希望它被验证为真实的电子邮件地址 HTML代码:PHP电子邮件验证和从HTML表单检索,php,html,validation,Php,Html,Validation,我一直在尝试创建一个表单来收集用户名、电子邮件和问题,但我对PHP太陌生了,所以我一直在努力使用它 目标是收集信息,当他们按submit时,他们的电子邮件地址应该被发送到我的电子邮件中,我希望它被验证为真实的电子邮件地址 HTML代码: <form method="post" action="process.php"> <fieldset> <legend>Personal Information</legend> <p><
<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 = 'myemail@myemail.com';
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);
检查mail()函数在php中的工作方式。
并检查下面的代码。祝你好运:)
检查mail()函数在php中的工作方式。
并检查下面的代码。祝你好运:)
查看mail函数在手册中接受的参数查看mail函数在手册中接受的参数
<?php
header("Content-type: text/html");
if(isset($_POST['submit'])){ //check if the submit button actually clicked
$name=$_POST["name"];
$question=$_POST["question"];
$email = test_input($_POST["recipient"]);
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { //php validations http://www.w3schools.com/php/php_form_url_email.asp
echo "Invalid email format";
}
$subject = "You have a USER INQUIRY:";
$to = 'myemail@myemail.com';
$message = "Name: {$name} \n";
$message .= "Email: {$email} \n";
$message .= "Question: {$question} \n";
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, $subject, $message);
}
<input id="recipient" name="recipient" type="email" required></p>