problem with php contact

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
shoyle
Forum Newbie
Posts: 21
Joined: Fri Jun 19, 2009 11:01 pm

problem with php contact

Post by shoyle »

Hi im making a contact form, and theres an error on the php, im getting this message on my browser:


Parse error: syntax error, unexpected T_IF in /xxxx/xxxxxx/xxxxxxxx/enviar.php on line 7

any litlle help is apreciated thanks! :)

Code: Select all

<?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&aacute;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 biggrin.gif
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.';
?>
Last edited by shoyle on Wed Jul 22, 2009 10:55 am, edited 1 time in total.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: problem with php contact

Post by jackpf »

You're missing a semi colon on line 4.
shoyle
Forum Newbie
Posts: 21
Joined: Fri Jun 19, 2009 11:01 pm

Re: problem with php contact

Post by shoyle »

thanks!!! it worked little detail that changed it all thanks a lot!! :P
shoyle
Forum Newbie
Posts: 21
Joined: Fri Jun 19, 2009 11:01 pm

Re: problem with php contact

Post by shoyle »

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!:D
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: problem with php contact

Post by jackpf »

Well, to check if something is numeric you can use the is_numeric() function.

To check if something is not null, you can use if($var != '') or if($var != null) or if(!empty($var)).
shoyle
Forum Newbie
Posts: 21
Joined: Fri Jun 19, 2009 11:01 pm

Re: problem with php contact

Post by shoyle »

Code: Select all

 
<?php
$nombre = $_POST['nombre'];
$telefono = $_POST['telefono'];
$mail = $_POST['email'];
 
//------------------------------------------------------//
 
 
if(!$mail == "" && (!strstr($mail,"@") || !strstr($mail,".")))
{
echo "<h2>Vuelva a la pagina anterior, ingrese una direccion de e-mail v&aacute;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 :D
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.");
}
 
// this is what i added **************
 
$pattern = '/[^0-9]/';
if (preg_match($pattern, $telefono)) {
echo "<h2>Vuelva a la pagina anterior, ingrese un numero de telefono valido.</h2>\n";
die ("Vuelva a la pagina anterior.");
    // $telefono contains invalid characters
}
 
 
if (empty($POST['mensaje'])) {
echo "<h2>Vuelva a la pagina anterior, rellene todas las casillas.</h2>\n";
die ("Vuelva a la pagina anterior.");
    // the user left the element empty
}
//--------------------------------------------------------------------------//
 
$header = 'From: ' . $mail . " rn";
 
 
$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 = 'mail@mymail.com';
$asunto = 'Contacto desde pagina web';
 
mail($para, $asunto, utf8_decode($mensaje), $header);
 
echo 'Su mensaje ha sido enviado correctamente.';
?> 
 
 
 
Post Reply