Si...in pratica bisogna fare un controllo sulla mail che inserisce il mittente
Qui ti spiega quello che voglio dire
Spero tu lo sappia applicare al mio form
Si...in pratica bisogna fare un controllo sulla mail che inserisce il mittente
Qui ti spiega quello che voglio dire
Spero tu lo sappia applicare al mio form
Codice PHP:<?
$mail_destinatario = "vincenzothebest@altervista.org";
$mail_mittente = $_POST['email'];
$mail_oggetto = "Invio dati da post";
$mail_nome = $_POST['nome'];
$mail_regione = $_POST['regione'];
$mail_messaggio = str_replace("@"," ",$_POST['messaggio']);
$mail_corpo = 'Sono '. $mail_nome . ', e vengo dalla ' . $mail_regione . ', il mio indirizzo email è ' . $mail_mittente . ' e invio il seguente messaggio. ' . $mail_messaggio . ' ';
$pattern="^[^@ ]+@[^@ ]+\.[^@ \.]+$";
$error=0;
foreach ($_POST as $key=>$dato)
if (empty($_POST[$key])) $error=1;
if (!ereg($pattern,$email)) $error=2;
if ($error != 0)
{
if (mail($mail_destinatario, $mail_oggetto, $mail_corpo, "From: $mail_mittente"))
echo "
E-mail inviata correttamente.
I seguenti dati son stati inviati a $mail_destinatario
Nome: $mail_nome
Regione: $mail_regione
Indirizzo email: $mail_mittente
Messaggio: $mail_messaggio";
else
echo "
Errore durante l'invio della e-mail a $mail_destinatario. Riprova!";
}
else
{
switch ($error)
{
case 1:
$messaggio= "compila tutti i campi";
break;
case 2:
$messaggio= "hai inserito una mail no valida";
break;
}
echo $messaggio;
}
?>
Non sempre essere l'ultimo è un male... almeno non devi guardarti le spalle
il mio profilo su PHPClasses e il mio blog laboweb
Grazie...Provo e ti faccio sapere subito...
Ho testato e non funziona...invia la mail comunque, pur inserendo una parola al posto di un vero indrizzo nel campo $mail mittente
Sapresti risolvere il problema? Grazie ancora
attento perchè il forum non mette i backquotes...
la stringa pattern è $pattern="^[^@ ]+@[^@ ]+\.[^@ \.]+$";
Prova così![]()
Favorites:
Short links, are better!
Ho apportato la correzione ma purtroppo invia la mail comunque!
Forse l'errore sta da qualche altra parte...
Prova con questo:
Codice PHP:$pattern = "^[^_.]([a-zA-Z0-9_]*[.]?[a-zA-Z0-9_]+[^_]){2}@{1}[a-z0-9]+[.]{1}(([a-z]{2,3})|([a-z]{2,3}[.]{1}[a-z]{2,3}))$";
![]()
Favorites:
Short links, are better!
Ho testato e purtroppo non funziona!
Cmq ho un altro problema con un altro form!
Il seguente form non fa riferimento ad altre pagine quindi non usa il metodo GET bensì il metodo POST!
Vorrei rendere obbligatori tutti i campi in questo form ma non ci riesco! Potresti darmi una mano?
Di seguito posto il form:
Come hai potuto notare ho impostato la regola che se il campo è vuoto spunta l'avviso e non fa inviare il form, però io lasciando qualche campo vuoto ho notato che il form viene inviato comunque! Dove ho sbagliato?Codice PHP:<?
// Show form to add your site
if(!isset($_POST['submit']))
{
?>
<center>
<table style="margin-top: 30px;" border="1" cellpadding="2" cellspacing="0" width="50%" class="content" align="center">
<tr class="title">
<form method="POST" name=form>
<input type="hidden" name="submit" value="1">
<td width="100%" colspan="2">
<p align="center"><? echo $text['73'] ?></td>
</tr>
<tr>
<td width="50%"><? echo $text['36'] ?> :</td>
<td width="50%"><input type="text" name="sitename" size="24" maxlength="50"></td>
</tr>
<tr>
<td width="50%"><? echo $text['37'] ?> :</td>
<td width="50%"><input type="text" name="url" size="24" maxlength="100"></td>
</tr>
<tr>
<td width="50%"><? echo $text['38'] ?> [ 88 x 31 ] :</td>
<td width="50%"><input type="text" name="buttonurl" size="24" maxlength="125"></td>
</tr>
<tr>
<td width="50%"><? echo $text['39'] ?> :</td>
<td width="50%"><input type="text" name="email" size="24" maxlength="75"></td>
</tr>
<tr>
<td width="50%"><? echo $text['137'] ?> :</td>
<td width="50%"><select name="country" onChange="showimage()"><?
// Selecting different flags directory 'images/flags'
$handle = opendir('images/flags');
while(false!==($file = readdir($handle)))
{
if($file != "." AND $file != "..")
{
if($file == "flag_oth.gif")
{
$selected = " selected";
}
else
{
$selected = " ";
}
echo "<option value=\"" . $file . "\"" . $selected . ">" . $file . "</option>\n";
}
}
closedir($handle);
?>
</select>[img]images/flags/flag_oth.gif[/img]</td>
</tr>
<tr>
<td width="50%" valign="top"><? echo $text['40'] ?> :</td>
<td width="50%"><textarea rows="7" name="description" cols="26"></textarea></td>
</tr>
<tr>
<td width="50%" valign="top"><? echo $text['22'] ?> :</td>
<td width="50%"><input type="password" name="pssw" size="12" maxlength="25"></td>
</tr>
<tr>
<td width="50%" valign="top"><? echo $text['22'] ?> [ <? echo $text['59'] ?> ]:</td>
<td width="50%"><input type="password" name="pssw2" size="12" maxlength="25"></td>
</tr>
<tr>
<td width="100%" valign="top" colspan="2">
<p align="center"><input type="submit" value="<? echo $text['72'] ?>"></td>
</tr>
</table>
</center>
<?
}
// Form has been submitted
if(isset($_POST['submit']))
{
// Checking if email isn't used before to register a website
$query = mysql_query("SELECT COUNT(1) FROM " . $table . "_sites WHERE email = '" . $_POST['email'] . "'");
$result = mysql_result($query,0);
// If email has been registered, give error
if(!empty($result))
{
?>
<table border="1" cellpadding="2" cellspacing="0" width="50%" class="content" align="center">
<tr class="title">
<td width="100%"><p align="center"><? echo $text['73'] ?></td>
</tr>
<tr>
<td width="100%"><? echo $text['74'] ?> ...
[url="javascript:history.go(-1)"]<< <? echo $text['20'] ?>[/url]</td>
</tr>
</table>
<?
}
else
{ // If email hasn't been registered, run script to add site
?>
<table border="1" cellpadding="2" cellspacing="0" width="50%" align="center">
<tr class="title">
<td width="100%"><p align="center"><? echo $text['73'] ?></td>
</tr>
<tr class="content">
<td width="100%">
<?
// If sitename wasn't filled in
if(empty($_POST['sitename']))
{
?>
<? echo $text['75'] ?>
[url="javascript:history.go(-1)"]<< <? echo $text['20'] ?>[/url]
<?
}
// If URL wasn't filled in
elseif(empty($_POST['url']))
{
?>
<? echo $text['76'] ?>
[url="javascript:history.go(-1)"]<< <? echo $text['20'] ?>[/url]";
<?
}
// If email wasn't filled in
elseif(empty($_POST['email']))
{
?>
<? echo $text['77'] ?>
[url="javascript:history.go(-1)"]<< <? echo $text['20'] ?>[/url]
<?
}
// If description wasn't filled in
elseif(empty($_POST['description']))
{
?>
<? echo $text['78'] ?>
[url="javascript:history.go(-1)"]<< <? echo $text['20'] ?>[/url]
<?
}
// If password / confirm password weren't filled in
elseif(empty($_POST['pssw']) OR empty($_POST['pssw2']))
{
?>
<? echo $text['79'] ?>
[url="javascript:history.go(-1)"]<< <? echo $text['20'] ?>[/url]
<?
}
else
{
// If passwords are not the same
if($_POST['pssw'] != $_POST['pssw2'] OR empty($_POST['pssw']) OR empty($_POST['pssw2']))
{
?>
<? echo $text['61'] ?> ...
[url="javascript:history.go(-1)"]<< <? echo $text['20'] ?>[/url]
<?
}
else
{
// Not encrypted version of password
$pssw = $_POST['pssw'];
// Encrypted version of password
$pssw_encrypted = md5($_POST['pssw']);
$_POST['country'] = str_replace("flag_","", $_POST['country']);
$_POST['country'] = str_replace(".gif","", $_POST['country']);
$date = date("dmY");