Jquery mobile email form with php script

Posted by Pablo Marino on Stack Overflow See other posts from Stack Overflow or by Pablo Marino
Published on 2012-07-04T16:07:43Z Indexed on 2012/07/05 3:16 UTC
Read the original article Hit count: 216

Filed under:
|
|
|

i'm working in a mobile website and i'm having problems with my email form The problem is that when I receive the mail sent through the form, it contains no data. All the data entered by the user is missing.

Here is the form code

<form action="correo.php" method="post" data-ajax="false">
<div>
<p><strong>You can contact us by filling the following form</strong></p>
</div>
<div data-role="fieldcontain">
<fieldset data-role="controlgroup" data-mini="true">
<label for="first_name">First Name</label>
<input id="first_name" placeholder="" type="text" />
</fieldset>
</div>
<div data-role="fieldcontain">
<fieldset data-role="controlgroup" data-mini="true">
<label for="last_name">Last name</label>
<input id="last_name" placeholder="" type="text" />
</fieldset>
</div>
<div data-role="fieldcontain">
<fieldset data-role="controlgroup" data-mini="true">
<label for="email">Email</label>
<input id="email" placeholder="" type="email" />
</fieldset>
</div>
<div data-role="fieldcontain">
<fieldset data-role="controlgroup" data-mini="true">
<label for="telephone">Phone</label>
<input id="telephone" placeholder="" type="tel" />
</fieldset>
</div>
<div data-role="fieldcontain">
<fieldset data-role="controlgroup" data-mini="true">
<label for="age">Age</label>
<input id="age" placeholder="" type="number" />
</fieldset>
</div>
<div data-role="fieldcontain">
<fieldset data-role="controlgroup" data-mini="true">
<label for="country">Country</label>
<input id="country" placeholder="" type="text" />
</fieldset>
</div>
<div data-role="fieldcontain">
<fieldset data-role="controlgroup">
<label for="message">Your message</label>
<textarea id="message" placeholder="" data-mini="true"></textarea>
</fieldset>
</div>
<input data-inline="true" data-theme="e" value="Submit" data-mini="true" type="submit" />
</form>

Here is the PHP code

<?
/* aqui se incializan variables de PHP */
if (phpversion() >= "4.2.0") {
        if ( ini_get('register_globals') != 1 ) {
                $supers = array('_REQUEST',
                                '_ENV',
                                '_SERVER',
                                '_POST',
                                '_GET',
                                '_COOKIE',
                                '_SESSION',
                                '_FILES',
                                '_GLOBALS' );

                foreach( $supers as $__s) {
                        if ( (isset($$__s) == true) && (is_array( $$__s
) == true) ) extract( $$__s, EXTR_OVERWRITE );
                }
                unset($supers);
        }
} else {
        if ( ini_get('register_globals') != 1 ) {

                $supers = array('HTTP_POST_VARS',
                                'HTTP_GET_VARS',
                                'HTTP_COOKIE_VARS',
                                'GLOBALS',
                                'HTTP_SESSION_VARS',
                                'HTTP_SERVER_VARS',
                                'HTTP_ENV_VARS'
                                 );

                foreach( $supers as $__s) {
                        if ( (isset($$__s) == true) && (is_array( $$__s
) == true) ) extract( $$__s, EXTR_OVERWRITE );
                }
                unset($supers);
        }
}

/*  DE AQUI EN ADELANTE PUEDES EDITAR EL ARCHIVO */
    /* reclama si no se ha rellenado el campo email en el formulario */

/* aquí se especifica la pagina de respuesta en caso de envío exitoso */
$respuesta="index.html#respuesta";
// la respuesta puede ser otro archivo, en incluso estar en otro servidor

/* AQUÍ ESPECIFICAS EL CORREO AL CUAL QUEIRES QUE SE ENVÍEN LOS DATOS
DEL FORMULARIO, SI QUIERES ENVIAR LOS DATOS A MÁS DE UN CORREO,
LOS PUEDES SEPARAR POR COMAS */
$para ="[email protected];" /* this is not my real email, of course */

/* AQUI ESPECIFICAS EL SUJETO (Asunto) DEL EMAIL */
$sujeto = "Mail de la página - Movil";

/* aquí se construye el encabezado del correo, en futuras
versiones del script explicaré mejor esta parte */ 
$encabezado = "From: $first_name $last_name <$email>";
$encabezado .= "\nReply-To: $email";
$encabezado .= "\nX-Mailer: PHP/" . phpversion();

/* con esto se captura la IP del que envío el mensaje */
$ip=$REMOTE_ADDR;

/* las siguientes líneas arman el mensaje */
$mensaje .= "NOMBRE: $first_name\n";
$mensaje .= "APELLIDO: $last_name\n";
$mensaje .= "EMAIL: $email\n";
$mensaje .= "TELEFONO: $telephone\n";
$mensaje .= "EDAD: $age\n";
$mensaje .= "PAIS: $country\n";
$mensaje .= "MENSAJE: $message\n";

/* aqui se intenta enviar el correo, si no se
tiene éxito se da un mensaje de error */
if(!mail($para, $sujeto, $mensaje, $encabezado))
{
    echo "<h1>No se pudo enviar el Mensaje</h1>";
    exit();
}
else
{
    /* aqui redireccionamos a la pagina de respuesta */
    echo "<meta HTTP-EQUIV='refresh' content='1;url=$respuesta'>";
}

?>

Any help please? Thanks in advance Pablo

© Stack Overflow or respective owner

Related posts about php

Related posts about jQuery