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!
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
<?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á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.';
?>