Ciao a tutti, vorrei aggiungere dei controlli al file php (che ho trovato in rete e modificato di conseguenza anche se a digiuno di php) di modo che i campi richiesti siano obbligatoriamente compilato e non vuoi altrimenti non viene inviata la mail. Come posso risolvere? Grazie mille. Di seguito allego il codice del form html e del fil invio.php.
Codice HTML:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=11" />
<meta http-equiv="X-UA-Compatible" content="chrome=1" />
<meta name="description" content="xxxxxxxxxxxx">
<meta name="robots" content="index, follow">
<meta http-equiv="content-language" content="it">
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<meta name="viewport" content="width=device-width">
<meta name="viewport" content="width=device-width, user-scalable=0, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0" />
<link href="../css/modulomail.css" rel="stylesheet" type="text/css" />
<style type="text/css">
body,td,th {
color: #FFFFFF;
}
</style>
</head>
<body>
<form name="contact_form" method="post" action="invio.php">
<table width="300" border="0" align="center" cellpadding="10" cellspacing="3" id="table_cliente">
<tr>
<td align="center">Informazioni del cliente</td>
</tr>
</table>
<table width="360" height="205"border="0" align="center" cellpadding="0" cellspacing="0" id="table_cont">
<tr>
<td width="30" height="200" align="center"><table width="100%" border="0" cellpadding="8" cellspacing="1" id="table1">
<tr>
<td width="30" valign="middle">Nome</td>
<td width="70" valign="middle"><input name="fname" type="text" placeholder="Inserisci il tuo nome"></td>
</tr>
<tr>
<td valign="middle">Mail</td>
<td valign="middle"><input name="text" type="mail" placeholder="Inserisci la tua mail"></td>
</tr>
<tr>
<td valign="middle">Telefono</td>
<td valign="middle"><input name="phone" type="text" size="10" maxlength="10"placeholder="Telefono"></td>
</tr>
<tr>
<td valign="middle">Oggetto</td>
<td valign="middle"><input name="subject" type="text" placeholder="Oggetto (es.Ordine)"></td>
</tr>
</table></td>
<td width="65%" height="205"align="center"><table width="100%" border="0" cellpadding="8" cellspacing="3" id="table2">
<tr>
<td valign="middle">Richiesto</td>
</tr>
<tr>
<td valign="middle">Richiesto</td>
</tr>
<tr>
<td valign="middle">Richiesto</td>
</tr>
<tr>
<td valign="middle"> </td>
</tr>
</table></td>
</tr>
</table>
<table width="300" border="0" align="center" cellpadding="10" cellspacing="3" id="table_mess">
<tr>
<td align="center">Il tuo messaggio</td>
</tr>
</table>
<table width="400" border="0" align="center" cellpadding="10" cellspacing="3" id="table_messaggio">
<tr>
<td width="40" align="center"></td>
</tr>
<tr>
<td align="center">Messaggio</td>
<td align="center"><textarea name="message" cols="35" rows="5" placeholder="Scrivi qui il tuo messaggio"></textarea></td>
<td align="center">Richiesto</td>
</tr>
<tr>
<td align="right"> </td>
<td align="center"><input type="reset" name="reset" value="Reset"/> <input type="submit" name="Submit" value="Submit"></td>
<td align="center"><img src="http://www.scriptgenerator.net/generator/html-php-contact-form-mailer-generator_files/validform.jpg" alt="HTML PHP contact form generator" width="20" height="20" /></td>
</tr>
</table>
</form>
</body>
</html>
Codice PHP:
<?php session_start();
if(isset($_POST['Submit'])) {
$youremail = 'miamail@alice.it';
$fromsubject = 'Mail proveniente dal sito mio';
$title = $_POST['title'];
$fname = $_POST['fname'];
$mail = $_POST['mail'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$to = $youremail;
$mailsubject = 'Masage recived from'.$fromsubject.' Contact Page';
$body = $fromsubject.'
La persona che ti ha contattato è '.$fname.'
Telefono: '.$phone.'
E-mail: '.$mail.'
Oggetto: '.$subject.'
Messaggio:
'.$message.'
|---------END MESSAGE----------|';
echo "<script>location='grazie.html'; </script>";
mail($to, $subject, $body);
unset($_SESSION['chapcha_code']);
} else {
echo 'Sorry, you have provided an invalid security code';
}
?>