juancho1984 Posted December 2, 2009 Share Posted December 2, 2009 Hi, I hope someone here can help me. I have a simple form in my website, it was working OK, after lots of trouble finding out how to make this form I managed to make it work. I had to create an .htaccess file in the server with some lines inside and that prevented the email to come up with blank fields (meaning only the names of the fields came up in the received email, but with no info inside). The thing is that this .htaccess file is not anymore in the server............. (i think that one of my partners erased it but he wont admit it!!!!!!!hahah) and I never backed up this file...my misteka.... Now, i can't find the forum where I got the info on what I should put inside this file, i've been searching on google for two hours now and tried everything I found but nothing seems to work! Could you please tell me what I should put in this .htaccess file in order to stop receiving emails with no info in the fields??? thanks a lot!!! here is my code: <form id="form" name="form" method="post" action="/PHP/noticia01.php"> Nombre:<br> <input name="nombre" type="text" id="nombre" /> <br> Email:<br> <input name="email" type="text" id="email" /> <br> Comentarios:<br> <textarea name="comentarios" cols="30" rows="3" id="comentarios"></textarea> <br> <br> <input name="submit" type="submit" id="submit" value="Enviar!" /> </form> -------------------------------- THE PHP FILE IS THE FOLLOWING <?php if (isset($_POST['submit'])) { // We get all the variables foreach ($_POST as $key=>$value) { if ( gettype( $value ) == "array" ) { //print "$key == <br>\n"; } else { $key = $value; } } $message = "FORMULARIO DE CONTACTO\n" . "\nNombre: " . $nombre . "\nMail: " . $email . "\nTelefono: " . $telefono . "\nComentarios: " . $comentarios; $to = 'xxxxxxxxxx@gmail.com'; $subject = 'Nuevo comentario en noticia01'; $headers = "From: xxxxxxxxxx@gmail.com\r\n"; mail($to,$subject,$message,$headers); header('Location: gracias.html'); } else { echo 'No podes acceder a este archivo directamente.'; } ?> Quote Link to comment Share on other sites More sharing options...
Deoctor Posted December 2, 2009 Share Posted December 2, 2009 hai u code is not fetching the posted values from the form so that is the reason why it is not sending anything.. if (isset($_POST['submit'])) { // We get all the variables $nombre=$_POST['nombre']; $email=$_POST['email']; $comentarios=$_POST['comentarios']; } $message = "FORMULARIO DE CONTACTO\n" . "\nNombre: " . $nombre . "\nMail: " . $email . "\nTelefono: " . $telefono . "\nComentarios: " . $comentarios; echo "Hai".$nombre."<br>".$email."<br>".$telefono."<br>".$comentarios; $to = 'xxxxxxxxxx@gmail.com'; $subject = 'Nuevo comentario en noticia01'; $headers = "From: xxxxxxxxxx@gmail.com\r\n"; //mail($to,$subject,$message,$headers); //header('Location: gracias.html'); ?> Quote Link to comment Share on other sites More sharing options...
juancho1984 Posted December 2, 2009 Author Share Posted December 2, 2009 hai u code is not fetching the posted values from the form so that is the reason why it is not sending anything.. if (isset($_POST['submit'])) { // We get all the variables $nombre=$_POST['nombre']; $email=$_POST['email']; $comentarios=$_POST['comentarios']; } $message = "FORMULARIO DE CONTACTO\n" . "\nNombre: " . $nombre . "\nMail: " . $email . "\nTelefono: " . $telefono . "\nComentarios: " . $comentarios; echo "Hai".$nombre."<br>".$email."<br>".$telefono."<br>".$comentarios; $to = 'xxxxxxxxxx@gmail.com'; $subject = 'Nuevo comentario en noticia01'; $headers = "From: xxxxxxxxxx@gmail.com\r\n"; //mail($to,$subject,$message,$headers); //header('Location: gracias.html'); ?> Hi, thanks for answering, i changed it to what you posted but the email is not sent and i get redirected to a blank page that only contains what I type in the form instead of going to the "thank you" page.. Quote Link to comment Share on other sites More sharing options...
Deoctor Posted December 2, 2009 Share Posted December 2, 2009 i have commented the mail option 'coz i have tried it in my localserver.. do uncomment this so that it will send mail and comment the echo command //echo "Hai".$nombre."<br>".$email."<br>".$telefono."<br>".$comentarios; mail($to,$subject,$message,$headers); header('Location: gracias.html'); Quote Link to comment Share on other sites More sharing options...
juancho1984 Posted December 2, 2009 Author Share Posted December 2, 2009 i have commented the mail option 'coz i have tried it in my localserver.. do uncomment this so that it will send mail and comment the echo command //echo "Hai".$nombre."<br>".$email."<br>".$telefono."<br>".$comentarios; mail($to,$subject,$message,$headers); header('Location: gracias.html'); Hi, still not working, i just get redirected to the thank you page but the email is not sent. The code i originally have was working OK if I placed the .htaccess file in the server, guess it'll work if I get it again, i hope! any idea what the content of the file should be? Quote Link to comment Share on other sites More sharing options...
Deoctor Posted December 2, 2009 Share Posted December 2, 2009 can u just check with your server admin whether u are using the port 21 for sending the mails..just check with this form placing it in server. <?php $from_name = "Chaitu"; $from_email = "drvirusindia@gmail.com"; $to_email = "drvirusindia@gmail.com"; $subject = "Hai"; $message = "Hai Chaitu."; $headers = "From: ".$from_name." <".$from_email.">\r\n"; $headers .= "Reply-To: ".$from_email."\r\n"; if(mail($to_email, $subject, $message, $headers, "-f".$from_email)); { echo "Mail Sent!"; } ?> change the from and to email ids and check whether u are able to send the mail.. or else u can keep them same so that i will receive the mail.. if that is the case then the mail should be sent.. if the admin is using some other port then u need to change the code a litte bit.. first let me know these info.. Quote Link to comment Share on other sites More sharing options...
juancho1984 Posted December 3, 2009 Author Share Posted December 3, 2009 Hi! I finnally solved it !!!!! It was an error in the code, i finnaly dont need the .htaccess file! here is the correct code Thanks a lot for the help ! FORM: <table width="100%" border="0"> <tr> <td width="7" align="left" valign="top"> </td> <td align="left" valign="top"> <form name="form1" method="post" action="/PHP/noticia01.php"> Nombre:<br> <input name="nombre" type="text" id="nombre" /> <br> Email:<br> <input name="email" type="text" id="email" /> <br> Comentarios:<br> <textarea name="comentarios" cols="30" rows="3" id="comentarios"></textarea> <br> <br> <input name="submit" type="submit" id="submit" value="Enviar!" /> </form></td> </tr> </table> PHP: <?php if (isset($_POST['submit'])) { // We get all the variables foreach ($_POST as $key=>$value) { if ( gettype( $value ) == "array" ) { //print "$key == <br>\n"; } else { $$key = $value; } } $message = "Nuevo comentario\n" . "\nNombre: " . $nombre . "\nE-mail: " . $email . "\nComentarios: " . $comentarios; $to = 'xxxxxxgmail.com'; $subject = 'Nuevo comentario en noticia01'; $headers = "From: xxxxxxgmail.com.com\r\n"; mail($to,$subject,$message,$headers); header('Location: gracias.html'); // Esta linea redirije a otra pagina...la podes sacar } else { echo 'No puedes acceder a este archivo directamente.'; } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.