dan_
09-04-2006, 10:57
ciao, ho realizzato due pagine in php,
nella prima c'è un form per l' invio mail con 2 campi
nella seconda pagina ( se tutto è andato bene ) dice ke la mail è stata spedita con successo.
Il problema è ke nn mi fa il controllo sui campi ( ovvero se nn scrivo niente non dovrebbe inviarmi la mail )
vi allego il codice delle 2 pagine:
pagina 1 / invio dati:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?
mail('miamail@mail.it', $_POST['subject'], $_POST['body']);
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>contatti</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="css/newland.css" rel="stylesheet" type="text/css" />
<link href="/css/myCss.css" rel="stylesheet" type="text/css" />
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_validateForm() { //v4.0
var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
if (val) { nm=val.name; if ((val=val.value)!="") {
if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
} else if (test!='R') { num = parseFloat(val);
if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
min=test.substring(8,p); max=test.substring(p+1);
if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
} if (errors) alert('The following error(s) occurred:\n'+errors);
document.MM_returnValue = (errors == '');
}
//-->
</script>
<style type="text/css">
<!--
body {
background-color: #99CC00;
}
-->
</style></head>
<body>
<table width="603" border="0" cellpadding="3" cellspacing="0">
<tr>
<td width="550" bgcolor="#99CC00"><h1 class="titolo">Info? Scrivimi! </h1>
<form name="frm_message" id="frm_message" method="post" action="messageSent.php">
<table width="513" border="0" align="left" cellpadding="5" cellspacing="0" bordercolor="#000000" bgcolor="#eeeeee">
<tr>
<td width="136" class="myCSS">Oggetto / mittente </td>
<td width="357"><input name="subject" type="text" id="subject" onblur="MM_validateForm('subject','','R');MM_validateForm('subject','','R');return document.MM_returnValue" /></td>
</tr>
<tr>
<td width="136" class="myCSS">Corpo del messaggio </td>
<td><textarea name="body" cols="40" rows="6" wrap="VIRTUAL" id="body" onchange="MM_validateForm('body','','R');MM_validateForm('body','','R');return document.MM_returnValue"></textarea></td>
</tr>
<tr>
<td width="136"> </td>
<td><input name="Submit" type="submit" onclick="MM_validateForm('emailAddress','','RisEmail');return document.MM_returnValue" value="_____Invia mail" /></td>
</tr>
</table>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
</form> </td>
</tr>
</table>
</body>
</html>
pagina 2 / mail inviata
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?
mail('miamail@mail.it', $_POST['subject'], $_POST['body']);
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>messaggio inviato con successo!</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="/css/myCss.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
body {
background-color: #99CC00;
}
-->
</style></head>
<body>
<a href="#top"><img src="images/spacer.gif" alt="Skip to main page content." width="1" height="1" border="0" align="left" /></a>
<table width="565" border="0" cellpadding="3" cellspacing="0">
<tr>
<td width="280" bgcolor="#99CC00"><h1 class="titolo">Messaggio inviato! </h1>
<p class="myCSS">Il tuo messaggio è stato spedito con successo. Ti risponderò al più presto.</p>
</td>
</tr>
</table>
</body>
</html>
dove ho sbagliato?? :rolleyes:
grazie.
nella prima c'è un form per l' invio mail con 2 campi
nella seconda pagina ( se tutto è andato bene ) dice ke la mail è stata spedita con successo.
Il problema è ke nn mi fa il controllo sui campi ( ovvero se nn scrivo niente non dovrebbe inviarmi la mail )
vi allego il codice delle 2 pagine:
pagina 1 / invio dati:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?
mail('miamail@mail.it', $_POST['subject'], $_POST['body']);
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>contatti</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="css/newland.css" rel="stylesheet" type="text/css" />
<link href="/css/myCss.css" rel="stylesheet" type="text/css" />
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_validateForm() { //v4.0
var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
if (val) { nm=val.name; if ((val=val.value)!="") {
if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
} else if (test!='R') { num = parseFloat(val);
if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
min=test.substring(8,p); max=test.substring(p+1);
if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
} if (errors) alert('The following error(s) occurred:\n'+errors);
document.MM_returnValue = (errors == '');
}
//-->
</script>
<style type="text/css">
<!--
body {
background-color: #99CC00;
}
-->
</style></head>
<body>
<table width="603" border="0" cellpadding="3" cellspacing="0">
<tr>
<td width="550" bgcolor="#99CC00"><h1 class="titolo">Info? Scrivimi! </h1>
<form name="frm_message" id="frm_message" method="post" action="messageSent.php">
<table width="513" border="0" align="left" cellpadding="5" cellspacing="0" bordercolor="#000000" bgcolor="#eeeeee">
<tr>
<td width="136" class="myCSS">Oggetto / mittente </td>
<td width="357"><input name="subject" type="text" id="subject" onblur="MM_validateForm('subject','','R');MM_validateForm('subject','','R');return document.MM_returnValue" /></td>
</tr>
<tr>
<td width="136" class="myCSS">Corpo del messaggio </td>
<td><textarea name="body" cols="40" rows="6" wrap="VIRTUAL" id="body" onchange="MM_validateForm('body','','R');MM_validateForm('body','','R');return document.MM_returnValue"></textarea></td>
</tr>
<tr>
<td width="136"> </td>
<td><input name="Submit" type="submit" onclick="MM_validateForm('emailAddress','','RisEmail');return document.MM_returnValue" value="_____Invia mail" /></td>
</tr>
</table>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
</form> </td>
</tr>
</table>
</body>
</html>
pagina 2 / mail inviata
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?
mail('miamail@mail.it', $_POST['subject'], $_POST['body']);
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>messaggio inviato con successo!</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="/css/myCss.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
body {
background-color: #99CC00;
}
-->
</style></head>
<body>
<a href="#top"><img src="images/spacer.gif" alt="Skip to main page content." width="1" height="1" border="0" align="left" /></a>
<table width="565" border="0" cellpadding="3" cellspacing="0">
<tr>
<td width="280" bgcolor="#99CC00"><h1 class="titolo">Messaggio inviato! </h1>
<p class="myCSS">Il tuo messaggio è stato spedito con successo. Ti risponderò al più presto.</p>
</td>
</tr>
</table>
</body>
</html>
dove ho sbagliato?? :rolleyes:
grazie.