Ciao a tutti
Ho questo codice PHP per mandare una mail dal mio sito. Bisogna riempire obbligatoriamente tutti i campi. Il mio problema è che io avrei bisogno un form con il solo campo del messaggio. Ovvero una finestrella in cui scrivere un messaggio e un pulsante INVIA. Nient'altro. Niente nome mittente, niente email... Chi mi sa aiutare? Potreste modificarmi il codice in modo che sia come l'ho bisogno io?
Grazie a chi mi vorrà aiutare!
<?php
$youraddress = "tuonome@email.it"; // Your e-mail address - duh
$subject_prefix = "[CONTACT] "; // What you want the subjects to be prefixed with - can be left blank
$timeoffset = "0"; // How many hours you are off your server
$name = stripslashes(strip_tags($_POST['name']));
$email = stripslashes(strip_tags($_POST['email']));
$subject = stripslashes(strip_tags($_POST['subject']));
$message = stripslashes(strip_tags($_POST['message']));
function emailform() {
global $name, $email, $subject, $message
// You can make this form look like whatever you want. All it needs
// to have are fields for "name", "email", "subject" and "message".
// The following is just a very simple one you can use or modify.
?><form name="emailform" method="post" action="">
<table width="380" border="0" cellspacing="0">
<tr><td width="608">
<fieldset>
<font size="2" face="verdana">
<legend>Tuo nome </legend>
<input name="nome" type="text" id="nome" tabindex="1" value="<?php echo $name; ?>" size="75" maxlength="250">
</font>
</fieldset>
</td>
</tr><tr height=5><td><font size="2" face="verdana"></font></td>
</tr><tr><td>
<fieldset>
<font size="2" face="verdana">
<legend>E-mail</legend>
<input type="text" name="email" size="75" maxlength="250" tabindex="2" value="<?php echo $email; ?>">
</font>
</fieldset>
</td>
</tr><tr height=10><td><font size="2" face="verdana"></font></td>
</tr><tr><td>
<fieldset>
<font size="2" face="verdana">
<legend>Data invio </legend>
<input name="data_invio" type="text" id="data_invio" tabindex="3" value="<?php echo $subject; ?>" size="75" maxlength="350">
</font>
</fieldset>
</td>
</tr><tr height=10><td><font size="2" face="verdana"></font></td>
</tr><tr><td>
<fieldset>
<font size="2" face="verdana">
<legend>Variazioni</legend>
<textarea name="variazioni_packers" id="variazioni_packers" cols="57" rows="7" tabindex="4"><?php echo $message; ?></textarea>
</font>
</fieldset>
</td>
</tr><tr height=10><td><font size="2" face="verdana"></font></td>
</tr><tr><td>
<fieldset>
<font size="2" face="verdana">
<legend></legend>
<input type="submit" name="submit" value=" E-Mail Me! ">
</font>
</fieldset>
</td>
</tr>
</table>
</form>
<?php }
if ($_POST['submit'] || isset($_POST['submit'])) {
if ($name == "" || !isset($name) || $email == "" || !isset($email) || $subject == "" || !isset($subject) || $message == "" || !isset($message)) {
echo "
YOU MUST FILL IN ALL FIELDS!</p>";
emailform();
} elseif (substr_count($email,"@") != 1 || substr_count($email,".") < 1) {
echo "
Invalid e-mail address!</p>";
emailform();
} else {
$time = time()+$timeoffset*3600;
$url = "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
$message = "
<html>
<head>
<title>E-Mail Sent From ".$url."</title>
</head>
<body>
The following was sent from <a href=\"".$url."\">".$url."</a>:
From: ".$name."
E-Mail Address: ".$email."
Subject: ".$subject."
User's IP Address: ".$_SERVER['REMOTE_ADDR']."
Sent At: ".date("l, F jS, Y h:i:s A",$time)."
Message:
".nl2br($message)."
</body>
</html>";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: ".$name." <".$email.">\r\n";
mail($youraddress,$subject_prefix.$subject,$messag e,$headers) or die("Sorry, there was an error when sending the e-mail.
Please contact <a href=\"mailto:".$youraddress."\">".$youraddress."</a>");
echo "E-mail successfully sent!";
}
} else {
echo "
All fields are required!</p>";
emailform();
}
?>