2016-04-24 15 views
1

Ich habe versucht, ein Formular zu erstellen, das den Namen, die E-Mail und die Frage eines Benutzers sammelt, aber ich bin so neu in PHP, dass ich wirklich damit zu kämpfen habe.PHP Email Validation und Retrieval von einem HTML-Formular

Das Ziel ist es, die Informationen zu sammeln, und wenn sie auf "Senden" drücken, wird ihre E-Mail-Adresse an meine E-Mail gesendet und ich möchte, dass sie als echte E-Mail-Adresse bestätigt wird.

HTML-Code:

<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 CODE:

<?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); 
+3

schauen Sie sich die Argumente an, die die Mail-Funktion im Handbuch akzeptiert –

Antwort

0

prüfen, wie mail() Funktion in PHP arbeitet here. Und überprüfen Sie diesen Code unten. Viel Glück :)

Und auch in Ihrem HTML können Sie sagen, Eingabe-Typ = E-Mail, die von vielen Browsern unterstützt wird.

<input id="recipient" name="recipient" type="email" required></p>