Visualizzazione dei risultati da 1 a 9 su 9

Discussione: form mail php

  1. #1
    Utente di HTML.it
    Registrato dal
    Apr 2008
    Messaggi
    170

    form mail php

    Ciao a tutti,
    premetto che mi sono appena iscritto a questo forum, e mi interesso al codice solo da pochi mesi, quindi chiedo scusa in anticipo per eventuali e banali errori d sintassi.
    Io ho fatto un form d'ordine simile a questo (inedx.html):



    <form action="mail_forum.php" method="post">
    Nome
    <input maxlength="40" name="nome" size="35" type="text" />

    e-mail
    <input maxlength="40" name="mail" size="35" type="text" />


    <select name="ordine1">
    <option selected="selected" value="none">none</option>
    <option value="prodotto1">Prodotto 1</option>
    <option value="prodotto2">Prodotto 2</option>
    </select>

    n.
    <input style="width:50px; height:18px;" type="text" name="ordine1n" value="0"/>


    <select name="ordine2">
    <option selected="selected" value="none">none</option>
    <option value="prodotto3">Prodotto 3</option>
    <option value="prodotto4">Prodotto 4</option>
    </select>

    n.
    <input style="width:50px; height:18px;" type="text" name="ordine2n" value="0"/>


    <input stile="position:relative; z-index:2;" type="submit" name="Submit" value="invia"/>
    </form>



    Il pulsante "INVIA", invia i dati ad un file simile a questo (mail_forum.php):



    <?php
    // L'INDIRIZZO DEL DESTINATARIO DELLA MAIL
    $to = "mail@mail.it";

    // IL SOGGETTO DELLA MAIL
    $subject = "ORDINE";

    // COSTRUZIONE DEL CORPO DEL MESSAGGIO
    $body = "Contenuto del modulo:\n\n";

    $body .= "nome: " . trim(stripslashes($_POST["nome"])) . "\n";
    $body .= "e-mail: " . trim(stripslashes($_POST["mail"])) . "\n";
    $body .= " "."\n";
    $body .= " "."\n";
    $body .= "1 ordine: " . trim(stripslashes($_POST["ordine1"])) . "\n";
    $body .= " quantità: " . trim(stripslashes($_POST["ordine1n"])) . "\n";
    $body .= " "."\n";
    $body .= "2 ordine: " . trim(stripslashes($_POST["ordine2"])) . "\n";
    $body .= " quantità: " . trim(stripslashes($_POST["ordine2n"])) . "\n";



    // INTESTAZIONI SUPPLEMENTARI
    $headers = "From:$mail";

    // INVIO DELLA MAIL
    if(@mail($to, $subject, $body, $headers)) { // SE L'INOLTRO E' ANDATO A BUON FINE...

    echo "mail inoltrata con successo.";

    } else {// ALTRIMENTI...

    echo "Si sono verificati dei problemi nell'invio della mail.";

    }

    ?>


    Questo file invia i dati contenuti nel form ad un indirizzo mail prestabilito.
    a questo punto avrei due domante:
    1. Come posso far si che in caso una select non sia stata selezionata dall'utente, anziche arrivare nella mail la voce:

    Ordine 1: none

    non arrivi niente?

    2.Come posso formattare il testo nel corpo della mail?

    P.S.
    aspetto ansioso un aiuto!
    ringrazio tutti in anticipo,
    mi scuso ancora per eventuali errori.

    P.P.S.
    il file .php l'ho preso da un form, non l'ho generato io.

  2. #2
    Utente di HTML.it L'avatar di kodode
    Registrato dal
    Sep 2002
    Messaggi
    1,896
    <?php

    //VERIFICO L'ESISTENZA DI ORDINE1
    if( $_POST["ordine1"] ){
    // L'INDIRIZZO DEL DESTINATARIO DELLA MAIL
    $to = "mail@mail.it";

    // IL SOGGETTO DELLA MAIL
    $subject = "ORDINE";

    // COSTRUZIONE DEL CORPO DEL MESSAGGIO
    $body = "Contenuto del modulo:\n\n";

    $body .= "nome: " . trim(stripslashes($_POST["nome"])) . "\n";
    $body .= "e-mail: " . trim(stripslashes($_POST["mail"])) . "\n";
    $body .= " "."\n";
    $body .= " "."\n";
    $body .= "1 ordine: " . trim(stripslashes($_POST["ordine1"])) . "\n";
    $body .= " quantità: " . trim(stripslashes($_POST["ordine1n"])) . "\n";
    $body .= " "."\n";
    $body .= "2 ordine: " . trim(stripslashes($_POST["ordine2"])) . "\n";
    $body .= " quantità: " . trim(stripslashes($_POST["ordine2n"])) . "\n";



    // INTESTAZIONI SUPPLEMENTARI
    $headers = "From:$mail";

    // INVIO DELLA MAIL
    if(@mail($to, $subject, $body, $headers)) { // SE L'INOLTRO E' ANDATO A BUON FINE...

    echo "mail inoltrata con successo.";

    } else {// ALTRIMENTI...

    echo "Si sono verificati dei problemi nell'invio della mail.";

    }
    }else{
    echo "CAMPO ORDINE OBBLIGATORIO";
    }
    ?>

    per la formattazione del corpo della mail dovresti riuscire formattandolo in HTML, però qui non so aiutarti molto

  3. #3
    Utente di HTML.it
    Registrato dal
    Apr 2008
    Messaggi
    170
    No, a me non serve che l'utente selezioni per forza tutte le select.
    il file originale ne ha 28...
    mi serve che quelle vhe lui non seleziona, non vengano visualizzate nella mail.
    P.S.
    html non funziona per formattare il corpo della mail.

  4. #4
    Utente di HTML.it L'avatar di kodode
    Registrato dal
    Sep 2002
    Messaggi
    1,896
    Codice PHP:

    <?php


    // L'INDIRIZZO DEL DESTINATARIO DELLA MAIL
    $to "mail@mail.it";

    // IL SOGGETTO DELLA MAIL
    $subject "ORDINE";

    // COSTRUZIONE DEL CORPO DEL MESSAGGIO
    $body "Contenuto del modulo:\n\n";

    $body .= "nome: " trim(stripslashes($_POST["nome"])) . "\n";
    $body .= "e-mail: " trim(stripslashes($_POST["mail"])) . "\n";
    $body .= " "."\n";
    $body .= " "."\n";
    //VERIFICO L'ESISTENZA DI ORDINE1
    if( $_POST["ordine1"] ){
            
    $body .= "1 ordine: " trim(stripslashes($_POST["ordine1"])) . "\n";
    }
    $body .= " quantità: " trim(stripslashes($_POST["ordine1n"])) . "\n";
    $body .= " "."\n";
    $body .= "2 ordine: " trim(stripslashes($_POST["ordine2"])) . "\n";
    $body .= " quantità: " trim(stripslashes($_POST["ordine2n"])) . "\n";



    // INTESTAZIONI SUPPLEMENTARI
    $headers "From:$mail";

    // INVIO DELLA MAIL
    if(@mail($to$subject$body$headers)) { // SE L'INOLTRO E' ANDATO A BUON FINE...

    echo "mail inoltrata con successo.";

    } else {
    // ALTRIMENTI...

    echo "Si sono verificati dei problemi nell'invio della mail.";


    ?>
    bastava spostare l'if
    html non funziona per formattare il corpo della mail.
    hai già provato? e se si, come hai provato?
    basta fare un piccola ricerca, ad esempio, il primo link che ho trovato io formatta in HMTL....
    http://www.senamion.it/2006/06/20/ph...rmattata-html/

  5. #5
    Utente di HTML.it
    Registrato dal
    Apr 2008
    Messaggi
    170
    con quella modifica al php mi da un messaggio d'errore...
    per la formattazione ok thanks.

  6. #6
    Utente di HTML.it L'avatar di kodode
    Registrato dal
    Sep 2002
    Messaggi
    1,896
    manca la chiusura finale della graffa...

  7. #7
    Utente di HTML.it
    Registrato dal
    Apr 2008
    Messaggi
    170
    ora arriva la mail ma anche
    ordine 1: none...
    il problema non è risolto.

  8. #8
    Utente di HTML.it L'avatar di kodode
    Registrato dal
    Sep 2002
    Messaggi
    1,896
    hai ragione ho sbagliato io...

    if( $_POST["ordine1"] != "none" ){ ....

  9. #9
    Utente di HTML.it
    Registrato dal
    Apr 2008
    Messaggi
    170
    ok, ora è perfetto.
    GRAZIE MILLE!!!
    Piano piano imparerò...

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 © 2025 vBulletin Solutions, Inc. All rights reserved.