Thursday, May 26, 2016

Code A Simple PHP Contact Form With A Reply To Option

Today I will show to how to code a Contact form in PHP Which also has a Reply To feature.It is very simple to do so using combination of HTML and PHP.

The Code for the form is given below:

Form Code:
<form action="procesar_form.php" method="post" name="formulario" id="formulario" onsubmit=return validarFormulario()>
<label for="nombre">Nombre </label>
<input type="text" name="nombre" id="nombre" size="60"/>

<label for="apellido">Apellido </label>
<input type="text" name="apellido" id="apellido" size="60"/>

<label for="email">Email </label>
<input type="text" name="email" id="email" size="60"/>

<label for="comentarios">Comentarios</label>
<textarea name="comentarios" id="comentarios" cols="44" rows="10"></textarea>

<input type="button" name="enviar" id="enviar" value="Enviar" onclick="validarFormulario()" /></textarea>

</form>

PHP Code
$email = $_POST[email];


$to = xyz@gmail.com;
$subject = Contacto Us;
$message = Name: . $_POST[name] . " " .
Surname: . $_POST[surname] . " " .
Email: . $_POST[email] . " " .
Comments: . $_POST[comments];
$headers = From: $email . " " .
Reply-to: $email . " " .
X-Mailer: PHP/ . phpversion();


mail($to, $subject, $message, $headers);


header("Location: ../../index.html");

Just put it all together and you are ready to go.I hope you enjoyed this free php script

Enjoy!