Jump to content

Problem With Contact Form


shoyle
 Share

Recommended Posts

Hi, im making a contact page and this is my php part, when i open it in my browser it says: Parse error: syntax error, unexpected T_IF in xx/xxxxx/xxxxx/xxxx.xx on line 7 :) and i dont understand why scince line 7 is empty...thanks a lot!

<?php$nombre = $_POST['nombre'];$mail = $_POST['email'];$telefono = $_POST['telefono'];//------------------------------------------------------//if(!$mail == "" && (!strstr($mail,"@") || !strstr($mail,"."))){echo "<h2>Vuelva a la pagina anterior, ingrese una direccion de e-mail válida-.</h2>\n";$badinput = "<h2>La informacion no fue ingresada.</h2>\n";echo $badinput;die ("Vuelva a la pagina anterior.");}//aca creo 1q dice: si los campos: visitante, mail de visitante, y nota estan vacios el resultado es: vuelva atraz rellene los campos vacios :)if(empty($nombre) || empty($telefono) || empty($mail)) {echo "<h2>Vuelva a la pagina anterior, rellene todas las casillas.</h2>\n";die ("Vuelva a la pagina anterior.");}//--------------------------------------------------------------------------//$header = 'From: ' . $mail . " rn";$header .= "X-Mailer: PHP/" . phpversion() . " rn";$header .= "Mime-Version: 1.0 rn";$header .= "Content-Type: text/plain";$mensaje = "Este mensaje fue enviado por " . $nombre . " ";$mensaje .= "Su telefono es: " . $telefono . " ";$mensaje .= "Su e-mail es: " . $mail . " ";$mensaje .= "Mensaje: " . $_POST['mensaje'] . " " ;$mensaje .= "Enviado el " . date('d/m/Y', time());//-----------------------------------------------------////----------------------------------------------------//$para = 'mymail@mymail.com';$asunto = 'Contacto desde pagina web';mail($para, $asunto, utf8_decode($mensaje), $header);echo 'Su mensaje ha sido enviado correctamente.';?> 

Edited by shoyle
Link to comment
Share on other sites

unexpected T_IF means the parser did not expect your if statement. Look at the first line of actual code before the if statement. You'll see that you left out the semi-colon to end the line. That is why the if statement was not expected. The parser thinks you're trying to put the if statement in the same line, and it doesn't understand what to do.

Link to comment
Share on other sites

unexpected T_IF means the parser did not expect your if statement. Look at the first line of actual code before the if statement. You'll see that you left out the semi-colon to end the line. That is why the if statement was not expected. The parser thinks you're trying to put the if statement in the same line, and it doesn't understand what to do.
it worked!! thanks a lot!!!! :) Edited by shoyle
Link to comment
Share on other sites

I want to add 2 things and i dont know how, im begeiner on php,on the "telefono" part, I want to make sure they type numbers, whats the "if" condition for that?and I also want to make sure they type a message whats the "if" for that? thanks!:)

Link to comment
Share on other sites

For your first question, something like this will work:

$pattern = '/[^0-9]/';if (preg_match($pattern, $telefono)) {	// $telefono contains invalid characters}

If a user leaves a form element empty, so that it does not get posted, then there will be no corresponding element in your $POST array. Test for that using isset() or empty(), like this:

if (empty($POST['my_message'])) {	// the user left the element empty}

You'll get an error if you try to access a non-existent array member in any other way.

Link to comment
Share on other sites

For your first question, something like this will work:
$pattern = '/[^0-9]/';if (preg_match($pattern, $telefono)) {	// $telefono contains invalid characters}

If a user leaves a form element empty, so that it does not get posted, then there will be no corresponding element in your $POST array. Test for that using isset() or empty(), like this:

if (empty($POST['my_message'])) {	// the user left the element empty}

You'll get an error if you try to access a non-existent array member in any other way.

Thanks!! works perfect!! :)
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...