harry_ord Posted November 14, 2016 Share Posted November 14, 2016 Hello, this is my site:http://feriapixel.cl/cleanway/index.htmlIn this index.html file i have a form with method post that takes all the input from the user and send it to formulario.php using post.This is the form: <form action="formulario.php" method="post"> <div class="form-group"> <input type="text" class="form-control" id="nombre" placeholder="Nombre" name="nombre"> </div> <div class="form-group"> <input type="text" class="form-control" id="nombre" placeholder="Apellido" name="apellido"> </div> <div class="form-group"> <input type="text" class="form-control" id="nombre" placeholder="Número Móvil" name="telefono"> </div> <div class="form-group"> <input type="mail" class="form-control" id="nombre" placeholder="Email" name="email"> </div> <button type="submit" class="btn btn-ganarplata">QUIERO GANAR MÁS PLATA<br> VENDIENDO CLEAN WAY</button> </form> And this is the formulario.php script: <?php header('Location: index.html'); $nombre = $_POST["nombre"]; $apellido = $_POST["apellido"]; $telefono = $_POST["telefono"]; $email = $_POST["email"]; // the message $msg = "<html> <head> <title>Formulario Clean Way</title> </head> <body> <p><b>Nombre:</b> <br> ". $nombre ." </p> <p><b>Apellido:</b> <br> ". $apellido ." </p> <p><b>Teléfono:</b> <br> ". $telefono ." </p> <p><b>Email:</b> <br> ". $email ." </p> </body> </html>" ; // More headers $headers .= 'Content-Type: text/html' . "\r\n"; // use wordwrap() if lines are longer than 70 characters $msg = wordwrap($msg,70); if ($_SERVER["REQUEST_METHOD"] == "POST") { // send email mail("felipepinoredes@gmail.com","Formulario Contacto",$msg, $headers); } ?> I never receive the message on my gmail inbox. What am i doing wrong?My site is hosted on Hostgator using a re-seller account, it's using PHP 7.0. Link to comment Share on other sites More sharing options...
Ingolme Posted November 14, 2016 Share Posted November 14, 2016 That header() function call is going to leave the page before the mail has a chance to get sent. Move it to the end of your code. Link to comment Share on other sites More sharing options...
dsonesuk Posted November 14, 2016 Share Posted November 14, 2016 It makes no difference, it may leave the page but the code continues to run, only with exit(); following the header() will it stop any further execution of code. IF you google 'hostgator php mail not sending' you will see there is a lot of issues with this, with lots of solutions. Link to comment Share on other sites More sharing options...
dsonesuk Posted November 14, 2016 Share Posted November 14, 2016 unrelated problem 1) multiple identical id ref, when they should be unique. 2) no such input attribute type value of 'mail', should be 'email' Link to comment Share on other sites More sharing options...
harry_ord Posted November 15, 2016 Author Share Posted November 15, 2016 All the sytanx error fixed, but it still doesn't send the email. <form action="formulario.php" method="post"> <div class="form-group"> <input type="text" class="form-control" id="nombre" placeholder="Nombre" name="nombre"> </div> <div class="form-group"> <input type="text" class="form-control" id="apellido" placeholder="Apellido" name="apellido"> </div> <div class="form-group"> <input type="text" class="form-control" id="telefono" placeholder="Número Móvil" name="telefono"> </div> <div class="form-group"> <input type="mail" class="form-control" id="email" placeholder="Email" name="email"> </div> <button type="submit" class="btn btn-ganarplata">QUIERO GANAR MÁS PLATA<br> VENDIENDO CLEAN WAY</button> </form> And the php file: <?php error_reporting(-1); ini_set('display_errors', 'On'); set_error_handler("var_dump"); $nombre = $_POST["nombre"]; $apellido = $_POST["apellido"]; $telefono = $_POST["telefono"]; $email = $_POST["email"]; // the message $msg = "<html> <head> <title>Formulario Clean Way</title> </head> <body> <p><b>Nombre:</b> <br> ". $nombre ." </p> <p><b>Apellido:</b> <br> ". $apellido ." </p> <p><b>Teléfono:</b> <br> ". $telefono ." </p> <p><b>Email:</b> <br> ". $email ." </p> </body> </html>" ; // More headers $headers = 'Content-Type: text/html' . "\r\n"; // use wordwrap() if lines are longer than 70 characters $msg = wordwrap($msg,70); if ($_SERVER["REQUEST_METHOD"] == "POST") { // send email mail("felipepinoredes@gmail.com","Formulario Contacto",$msg, $headers); } ?> Link to comment Share on other sites More sharing options...
dsonesuk Posted November 15, 2016 Share Posted November 15, 2016 (edited) IT DOES SEND EMAIL, BUT! not apparently through hostgator, as mentioned before, this issue has been brought up many times, you need to contact hostgator for the best method/code used to make it pass through mail server and send email. This! <input type="mail" STILL WRONG! Edited November 15, 2016 by dsonesuk Link to comment Share on other sites More sharing options...
harry_ord Posted November 15, 2016 Author Share Posted November 15, 2016 Ok, i made some changes, now i have everything in the same index.php file.The form is like this: <form action="index.php" method="post"> <div class="form-group"> <input type="text" class="form-control" id="nombre" placeholder="Nombre" name="nombre"> </div> <div class="form-group"> <input type="text" class="form-control" id="nombre" placeholder="Apellido" name="apellido"> </div> <div class="form-group"> <input type="text" class="form-control" id="nombre" placeholder="Número Móvil" name="telefono"> </div> <div class="form-group"> <input type="mail" class="form-control" id="nombre" placeholder="Email" name="email"> </div> <button type="submit" name="submit" id="submit" class="btn btn-ganarplata">QUIERO GANAR MÁS PLATA<br> VENDIENDO CLEAN WAY</button> <p class="firma">www.cleanway.cl/</p> </form> The php is at the beginning of the file and is like that: <?php $nombre = $_POST['nombre']; $apellido = $_POST['apellido']; $telefono = $_POST['telefono']; $mail = $_POST['mail']; $from = 'From: Cleanway'; $to = 'alteizen@gmail.com'; $subject = 'Formulario de contacto Cleanway'; $body ="De: $nombre\n $apellido\n E-Mail: $mail\n Fono: $telefono\n "; ?> <? if ($_POST['submit']) { if (mail ($to, $subject, $body, $from)) { echo '<p>Su mensaje ha sido enviado</p>'; } else { echo '<p>No se pudo mandar su mensaje</p>'; } } ?> And know i'm sure that Hostgator DO SEND THE MAILS. How? because if i delete this condition condition"if ($_POST['submit']) {}"The mail is sent automatically to alteizen@gmail.com. So the problem is with the if statement. Link to comment Share on other sites More sharing options...
dsonesuk Posted November 15, 2016 Share Posted November 15, 2016 You need to add value attribute value="submit" to button, and to check if value set use if(isset($_POST['submit'])) Link to comment Share on other sites More sharing options...
harry_ord Posted November 15, 2016 Author Share Posted November 15, 2016 That was the problem! now it's solved.I always thought that the value attribute was just what was written in the button. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now