Good evening to everybody!
I have an app created with HTML5, Javascript and JqueryMobile with Phonegap.
I’m trying to create a form sending an easy email.
I tryed using an external php file but it not working. Following you can see the codes and I hope that somebody could help me.
THANKS!
file.html
<script src="js/invio-email.js"></script>
....
....
....
<form action="http://www.mysite.net/hdl-data.php" id="formail" method="post">
Nome:*<input id="nome" name="nome" type="text" size="40" required />
E-mail:*<input id="email" name="email" type="text" size="60" required />
Età del lettore:*<input id="etalettore" name="etalettore" type="text" size="10" required />
Genere letterario preferito:*<input id="genere" name="genere" type="text" size="40" required />
Ultimo libro letto:*<input id="ultimolibro" name="ultimolibro" type="text" size="40" required />
Note:<textarea id="note" cols="20" rows="5" name="note"></textarea>
<input id="invia" name="invia" type="submit" value="Invia" />
</form>
</div>
</body>
</html>
following the js file invio-email.js
$(document).ready(function() {
// Bind this action as a function to be executed when the button is clicked...
$('input[type="submit"][value="invia"]').click(function() {
$.post('http://www.mysite.net/hdl-data.php', {
nome: $('#nome').val(),
email: $('#email').val(),
etalettore: $('#etalettore').val(),
genere: $('#genere').val(),
ultimo-libro: $('#ultimolibro').val(),
note: $('#note').val()
// HTML function
}, function (html) {
// Place the HTML in a astring
var response=html;
// PHP was done and email sent
if (response=="success") {
alert("Message sent!");
} else {
// Error postback
alert("Please fill all fields!");
return false;
}
});
});
});
At the end there is the the php file hdl-data.php
<?php
// VARS
$nome=$_POST["nome"];
$email=$_POST["email"];
$etalettore=$_POST["etalettore"];
$genere=$_POST["genere"];
$ultimolibro=$_POST["ultimolibro"];
$note=$_POST["note"];
$Headers = "From:" . $email;
//VALIDATION
if(
$nome=="" ||
$Email=="" ||
$etalettore=="" ||
$genere=="" ||
$ultimolibro=="" ||
$note==""
) {
echo "Error";
} else {
mail("myemail@email.net","mobile app message",$nome, $Headers);
echo "Success";
}
?>