Visualizzazione dei risultati da 1 a 3 su 3

Discussione: Aiuto codice

  1. #1

    Aiuto codice

    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();
    }

    ?>

  2. #2
    Spero che sia quello che volevi...
    Graficamente è da sistemare!
    Codice PHP:
    <?php

    $youraddress 
    "pippo@pippo.com"// 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

    $message stripslashes(strip_tags($_POST['message']));

    function 
    emailform() {

    global 
    $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="<?php echo $PHP_SELF ?>">

    <table width="380" border="0" cellspacing="0"><tr><td width="608">

    <fieldset>
    <font size="2" face="verdana">
    <legend>[b]Messaggio[/b]</legend>
    <textarea name="message" id="message" 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 (
    $message == "" || !isset($message)) {
        echo 
    "

    [b]Il campo messaggio è obbligatorio![/b]</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>:



    [b]Subject:[/b] "
    .$subject_prefix."

    [b]User's IP Address:[/b] "
    .$_SERVER['REMOTE_ADDR']."

    [b]Sent At:[/b] "
    .date("l, F jS, Y h:i:s A",$time)."



    [b]Message:[/b]



    "
    .nl2br($message)."
    </body>
    </html>"
    ;

    $headers "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

    mail($youraddress,$subject_prefix,$message,$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 
    "

    [b]Campo messaggio obbligatorio[/b]</p>"
    ;
    emailform();
    }

    ?>
    Dovunque si va, non si può fare a meno di incontrare persone intelligenti. È divenuta una vera peste.
    Oscar Wilde

  3. #3
    Ciao, grazie mille! E' quello che volevo!
    Il problema è che quando provo a spedire il messaggio mi dice "mi dispiace, ma il campo messaggio è obbligatorio", anche se è stato compilato...

    Guarda... l'ho uploadato qui:

    http://www.lacasadipaolo.com/cfl/gestione/email.php

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.