Xalsar Xalsar - 2 months ago 5x
HTML Question

I do not now why my form fails

I wrote this html and php code to send a form, but I do not understand why it fails.

my code :


<form action="formulari.php" method="post">
Nombre:<input name= "name" type="text";>
email:<input name= "email" type="text";>
<p>Comentario:<textarea rows="4" cols="50">
</textarea name= "message"></p>
<input type="submit" value="enviar" >
<input type="reset" value="borrar" >


$name = $_POST [ 'name'];
$email = $_POST [ 'email'];
$message = $_POST['comentari'];
$to = "email@gmail.com";
$subject = "Formulari_contacte";

mail ( $to, $subject, $message, $email);
header('Location: ../index.html?message=form_submitted');


Can anyone help ?


Try the following:


<form action="formulari.php" method="post">
    <p>Nombre: <input name="name" type="text"></p>

    <p>email: <input name="email" type="text"></p>

    <p>Comentario: <textarea rows="4" cols="50" name="message"></textarea></p>

    <input type="submit" value="enviar">
    <input type="reset" value="borrar">


$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$to = "xavicarreragimbert@gmail.com"; 
$subject = "Formulari_contacte";

$mail = mail( $to, $subject, $message, $email);

// Check if email is send
if( $mail ) {
    header('Location: ../index.html?message=form_submitted');
} else {
    echo 'Email not send';

I removed the ";" and unnecessary spaces in HTML and PHP. You also had the name of the textarea in the closing tag.

Also note that you are open for injection. Users are able to write some javascript code to you.