Visualizzazione dei risultati da 1 a 2 su 2
  1. #1

    Script per l'invio mail: funziona ma modificato da i numeri

    Gentili esperti,
    ho questo codice per l'invio di una mail con allegato perfettamente funzionante:

    Codice PHP:
     <html>
    <head>
    <title>MMKit Tutorial - Send mail with attach</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <body bgcolor="#D2D2D2" leftmargin="3" topmargin="3" marginwidth="0" marginheight="0" text="#000000">
    <?
    function validate_upload($thefile) {
        global 
    $thefile_type$thefile_name$thefile_size;
      
    $my_max_file_size     "102400"# in bytes

        
    $registered_types = array(
                        
    "application/msword" => ".doc",
                        
    "application/octet-stream" => ".doc"
                        
    ); # these are only a few examples, you can find many more!
        
    $allowed_types = array("application/msword""application/octet-stream");
        
    $start_error "\n";
        if (
    $thefile == "none") { # do we even have a file?
            
    $error .= "\n- Nessun documento allegato.
    "
    ;
        } else { 
    # check if we are allowed to upload this file_type
            
    if ($thefile_size>$my_max_file_size$error .= "\n- Il file allegato supera la dimensione massima consentita.
    "
    ;
            if (!
    in_array($thefile_type$allowed_types)) {
                
    $error .= "\n- Il file che hai inserito non &egrave; del tipo richiesto:
                            
    \n"
    ;
                while (
    $type current($allowed_types)) {
                    
    $error .= "\n" $registered_types[$type] . " (" $type ")
    "
    ;
                    
    next($allowed_types);
                }
                
    $error .= "\n";
            }
            if (
    $error) {
                
    $error $start_error $error "\n";
                return 
    $error;
            } else {
                return 
    false;
            }
        }
    # END validate_upload
    ?> 
    <font face="Arial, Helvetica, sans-serif" size="2">

    <?
    if ($op=="invio") {
        
    $error=0;
        
    $msg="";
        if (
    $nome=="") {
            
    $error=1;
            
    $msg.="- Il campo nome è vuoto.
    "
    ;
        }
        if (
    $cognome=="") {
            
    $error=1;
            
    $msg.="- Il campo cognome è vuoto.
    "
    ;
        }
        if (
    $email=="") {
            
    $error=1;
            
    $msg.="- Il campo email è vuoto.
    "
    ;
        }
        if (
    $email!="" && !eregi("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3}$",$email)) {
            
    $error=1;
            
    $msg.="- L'email inserita non è valida.
    "
    ;    
        }
        if (
    $commento=="") {
            
    $error=1;
            
    $msg.="- Il campo commento è vuoto.
    "
    ;
        }
        
    $error_file="";
        if (!
    $thefile || $thefile=="none" || $thefile=="") {
            
    $error=1;
            
    $msg.="- Non hai inserito il curriculum.
    "
    ;
        } else 
    $error_file validate_upload($thefile);
        if (
    $error==|| $error_file!="") {
            echo
    "

    Attenzione! Si sono verificati i seguenti errori:
    $msg
    $error_file
    <a href=\"javascript:history.back()\">Clicca qui</a> per reinserire i dati."
    ;    
        } else {
            
    $emailto="myemail@mysite.com"// INERIRE L'EMAIL QUI!!
            
    $data=date("j/m/Y");
            
    $ora=date("h:i:s");
            
            
    $headers "MIME-Version: 1.0\n";
            
    $headers .= "Content-Type: multipart/mixed; boundary=\"XX-1234DED00099A\"\n";
            
    $headers .= "Content-Transfer-Encoding: 7bit\n";
            
    $headers .= "From: $email\n";
            
            
    $messaggio="--XX-1234DED00099A\n";
            
    $messaggio.="Content-Type: text/plain; charset=iso-8859-1\n";
            
    $messaggio.="Content-Transfer-Encoding: 7bit\n\r";

            
    $messaggio.="Curriculum inviato il $data alle $ora\n\r\nDati inseriti\n";
            
    $messaggio.="Nome: $nome\n\rCognome: $cognome\n";
            if (
    $telefono!=""$messaggio.="Telefono: $telefono\n";
            
    $messaggio.="Email: $email\nCommento:\n$commento\n";
            
    $oggetto_send="Invio Curriculum";
            
            
            
    $messaggio.="--XX-1234DED00099A\n";
            
    $messaggio.="Content-Type: application/octet-stream; name=\"curriculum.doc\"\n";
            
    $messaggio.="Content-Transfer-Encoding: base64\n";
            
    $messaggio.="Content-Description: \"Curriculum\"\n";
            
    $messaggio.="Content-Disposition: attachment\n\r";
            
            
    $fp=@fopen($thefile"r");
            if (
    $fp) {
                
    $data fread($fpfilesize($thefile));    
            }
            
    $curr base64_encode($data);
            
    $messaggio .= "$curr\n\r--XX-1234DED00099A--\n";
            if (!
    mail($emailto$oggetto_send$messaggio$headers)) {
                echo
    "
    [b]Attenzione.[/b]
    Si sono verificati degli errori durante l'invio della Email.

                Vi preghiamo di riprovare <a href=\"javascript: history.back()\">cliccando qui.</a>

                Se l'errore persiste Vi invitamo a riprovare più tardi. Grazie."
    ;
            }
            else {
                
    $messaggio_risposta="Grazie per averci contattato.\n\rIl vostro curriculum è stato inoltrato al responsabile del personale.\n\r\n\rDati inseriti\n";
                
    $messaggio_risposta.="Nome: $nome\n\rCognome: $cognome\n\r";
                if (
    $telefono!=""$messaggio_risposta.="Telefono: $telefono\n\r";
                
    $messaggio_risposta.="Commento:\n\r$commento\n\r\n\r";
                
    $messaggio_risposta.="Distinti saluti,\n\r";
                
    $oggetto2="Curriculum inoltrato";
                
    mail($email$oggetto2$messaggio_risposta,"From: NOME_SITO <$emailto>");
                echo 
    "
    [b]Email inviata correttamente.[/b]

                
    I dati inseriti sono i seguenti:

    "
    ;
                echo
    "Nome:[b] $nome [/b]

                Cognome:[b] 
    $cognome[/b]
    "
    ;
                if (
    $telefono!="") echo"Telefono: [b]$telefono[/b]
    "
    ;
                echo
    "Email: [b]$email[/b]
    Commento:[b] "
    .nl2br($commento)."[/b]

                

    Grazie per averci contattato."
    ;
            }
        }
        
    } else {
    ?>
                

    Form per invio curriculum


          <form enctype="multipart/form-data" method="post" action="<?=$PHP_SELF?>" name="contatti">
            <table width="550" border="0" cellspacing="3" cellpadding="0">
              <tr> 
                <td>Nome *</td>
                <td> 
                  <input type="text" name="nome" size="30">
                </td>
              </tr>
              <tr> 
                <td>Cognome *</td>
                <td> 
                  <input type="text" name="cognome" size="30">
                </td>
              </tr>
              <tr> 
                <td>Telefono</td>
                <td> 
                  <input type="text" name="telefono" size="30">
                </td>
              </tr>
              <tr> 
                <td>Email *</td>
                <td> 
                  <input type="text" name="email" size="30">
                </td>
              </tr>
              <tr> 
                <td>Allega il tuo curriculum
    (formato .doc - Max 100 Kb) *</td>
                <td>
                  <input type="hidden" name="MAX_FILE_SIZE" value="102400"> 
                  <input name="thefile" type="file" SIZE="35">
                </td>
              </tr>
              <tr> 
                <td>Commento *</td>
                <td> 
                  <textarea name="commento" wrap="VIRTUAL" cols="30" rows="5"></textarea>
                </td>
              </tr>
              <tr> 
                <td colspan="2">
                  <div align="center">
                      <input type="hidden" name="op" value="invio">
                    <input type="submit" name="Submit" value="Invia">
                    <input type="reset" name="Submit2" value="Reimposta">
                  </div>
                </td>
              </tr>
            </table>
          </form>
          <font size="1">I campi con l'asterisco sono obbligatori.

          <?
    }
    ?> 
           </font>
          
    </table>
    </body>

    </html>

    ---CONTINUA-----------------
    Eccoti!

  2. #2
    provo a modificarlo in questo modo



    Codice PHP:
     <?php 
        ob_start
    ();
        include(
    "check.php");
        
    error_reporting(E_ALL);
         
    ?>
    <table width="428" border="0" cellpadding="0" cellspacing="0" > 
    </tr> 
       <?php 
                  $slash 
    count(explode("/"$_SERVER["SCRIPT_NAME"]))-2;
                  
    $path="";      
                  for(
    $a=0$a<$slash;  $a++) $path.="../";
                  echo 
    "<tr>";
                  echo  
    "<td height=\"23\" colspan=\"2\" valign=\"top\" style=\"padding:15\" class=\"tah11\">";
                  echo  
    " </tr>";
      
    ?> 
      <tr> 
        <td  colspan="2" valign="top">
        <?
    // RENDIAMO LO SCRIPT COMPATIBILE CON LE VERSIONI DI PHP < 4.1.0
    if(!isset($_POST)) $_POST $HTTP_POST_VARS;
    if(!isset(
    $_FILES)) $_FILES $HTTP_POST_FILES;

    function 
    validate_upload($thefile) {
            global 
    $thefile_type$thefile_name$thefile_size;
      
    $my_max_file_size "9999999999"# in bytes

            
    $registered_types = array(
                                            
    "application/msword" => ".doc"
                                            
    ); # these are only a few examples, you can find many more!
            
    $allowed_types = array("application/msword");
            
    $start_error "\n";
            if (
    $thefile == "none") { # do we even have a file?
                    
    $error .= "\n- Nessun documento allegato.
    "
    ;
            } else { 
    # check if we are allowed to upload this file_type
                    
    if ($thefile_size $my_max_file_size$error .= "\n- Il file allegato supera la dimensione massima consentita.
    "
    ;
                    if (!
    in_array($thefile_type$allowed_types)) {
                            
    $error .= "\n- Il file che hai inserito non &egrave; del tipo richiesto:
                                                    
    \n"
    ;
                            while (
    $type current($allowed_types)) {
                                    
    $error .= "\n" $registered_types[$type] . " (" $type ")
    "
    ;
                                    
    next($allowed_types);
                            }
                            
    $error .= "\n";
                    }
                    if (
    $error) {
                            
    $error $start_error $error "\n";
                            return 
    $error;
                    } else {
                            return 
    false;
                    }
            }
    # END validate_upload

    ?> 
    <?
    if ($_POST['op']=="invio") {
            
    $error=0;
            
    $msg="";
            if (
    $_POST['ltea']=="" && $_POST['ltec']=="" && $_POST['ltmc']=="" && $_POST['ltsse']=="" && $_POST['lscpa']=="" && $_POST['lsem']=="" && $_POST['lsmk']=="" && $_POST['lss']=="" && $_POST['lqec']=="" && $_POST['lqsse']=="" ) {
                      
    $error=1;
                    
    $msg.="- Non è stato selezionato alcun Corso di Laurea.
    "
    ;
           }
     
            if (
    $disciplina=="") {
                    
    $error=1;
                    
    $msg.="- Il campo Disciplina non è stato compilato.
    "
    ;
            }
            
            
    $error_file="";
            if (!
    $thefile || $thefile=="none" || $thefile=="") {
                    
    $error=1;
                    
    $msg.="- Non ha inserito l'allegato.
    "
    ;
            } else 
    $error_file validate_upload($thefile);
            if (
    $error==|| $error_file!="") {
                    echo
    "

    Attenzione! Si sono verificati i seguenti errori:
    $msg
    $error_file
    <a href=\"javascript:history.back()\">Clicchi qui</a> per reinserire i dati."
    ;        
            } else {

    // parte modificata

    $attach    $_FILES["thefile"]["tmp_name"];
    $file_name $_FILES["thefile"]["name"];
    $file_type $_FILES["thefile"]["type"];
    $file_size $_FILES["thefile"]["size"];
    $file = @fopen($attach"r");
    $contents = @fread($file$file_size);
    $curr chunk_split(base64_encode($contents));
    @
    fclose($file);

    $boundary "XX-1234DED00099A";  // messo in un array per maggior facilità d'uso
                    
    $email="curiositydidnotkillthecat@hotmail.com";
                    
    $emailto="curiositydidnotkillthecat@hotmail.com"// INSERIRE L'EMAIL QUI!!
                    
    $data=date("j/m/Y");
                    
    $ora=date("h:i:s");

                    
    $headers  "MIME-Version: 1.0\n";
                    
    $headers .= "Content-Type: multipart/mixed; boundary=\"$boundary\"\n";
                    
    $headers .= "Content-Transfer-Encoding: 7bit\n";
                    
    $headers .= "From: $email\n";
                    
    $headers .= "X-attachments: $file_name\n";

                    
    $oggetto_send="$file_name";

                    
    $messaggio="--$boundary\n";
                    
    $messaggio.="Content-Type: text/plain; charset=us-ascii\n";
                    
    $messaggio.="Content-Transfer-Encoding: 7bit\n\r";
                    
    $messaggio.="Curriculum inviato il $data alle $ora\n\r\nDati inseriti\n";
                    
    $messaggio.="Email: $_POST[email]";
                    
    $messaggio.="--$boundary\n";
                    
    $messaggio.="Content-Type: $file_type; name=\"$file_name\"\n";
                    
    $messaggio.="Content-Transfer-Encoding: base64\n";
                    
    $messaggio.="Content-Disposition: attachment; filename=\"$file_name\"\n\n";
                    
    $messaggio.="$curr\n";
                    
    $messaggio.="--$boundary--\n";


                    if (!
    mail($emailto$oggetto_send$messaggio$headers)) {
                            echo 
    "
    [b]Attenzione.[/b]
    Si sono verificati degli errori durante l'invio della Email.

                            Vi preghiamo di riprovare <a href=\"javascript: history.back()\">cliccando qui.</a>

                            Se l'errore persiste Vi invitamo a riprovare più tardi. Grazie."
    ;
                    }
                    else {
                            
    $messaggio_risposta="Grazie per averci contattato.\n\rIl vostro contributo è stato inoltrato al responsabile.\n\r\n\rDati inseriti\n";
                            
    $messaggio_risposta.="File allegato: $file_name\n\r\n\r";
                            
    $messaggio_risposta.="Commento:\n\r$commento\n\r\n\r";
                            
    $messaggio_risposta.="Distinti saluti.\n\r";
                            
    $oggetto2="programma inviato a [url]www.economia.uniba.it[/url]";
                            
    $email="curiositydidnotkillthecat@hotmail.com";
                            
    mail($email$oggetto2$messaggio_risposta,"From: Michle Scalera <$emailto>");
                            echo 
    "
    [b]Email inviata correttamente.[/b]

                            
    I dati inseriti sono i seguenti:

    "
    ;
                             echo 
    "File allegato:[b] $file_name[/b]
    "
    ;
                                            }
            }
            
    } else {
    ?><table width="100%" cellpadding="0" cellspacing="0" border="0">

                    <tr>
                            <td></td>
                            <td width="100%" background="../immagini/top1bg.jpg"></td>
                    </tr>
                    </table>
                           [b] Benvenuto [/b]

                           Attraverso la compilazione del modulo qui di seguito &egrave; possibile inviare il proprio programma
                            

          <form enctype="multipart/form-data" method="post" action="<?=$PHP_SELF?>" name="contatti" class="tahform10" width="650">
    <table width="650" border="0" cellspacing="3" cellpadding="0" class="tahform10">
                <tr>
                <td>[b]Corso di Laurea*[/b]</td>
                <td><label>Laurea Triennale in Economia Aziendale</label></td>
                <td><input type="checkbox" name="ltea" value="ltea"></td>
              </tr>
              <tr>
                <td></td>
                <td>Laurea Triennale in Economia e Commercio </td>
                <td><input type="checkbox" name="ltec" value="ltec"></td>
              </tr>
              <tr>
                <td></td>
                <td>Laurea Triennale in Marketing e Comunicazione</td>
                <td><input type="checkbox" name="ltmc" value="ltmc"></td>
              </tr>
              <tr>
                <td></td>
                <td>Laurea Triennale in Scienze Statistiche ed Economiche</td>
                <td><input type="checkbox" name="ltsse" value="ltsse"></td>
              </tr>
              <tr>
                <td></td>
                <td>Laurea Magistrale in Consulenza Professionale per le Aziende</td>
                <td><input type="checkbox" name="lscpa" value="lscpa"></td>
              </tr>
              <tr>
                <td></td>
                <td>Laurea Magistrale in Economia e Management</td>
                <td><input type="checkbox" name="lsem" value="lsem"></td>
              </tr>
              <tr>
                <td></td>
                <td>Laurea Magistrale in Marketing </td>
                <td><input type="checkbox" name="lsmk" value="lsmk"></td>
              </tr>
              <tr>
                <td></td>
                <td>Laurea Magistrale in Statistica per le Decisioni Socio Economico e Finanziarie </td>
                <td><input type="checkbox" name="lss" value="lss"></td>
              </tr>
              <tr>
                <td></td>
                <td><label>Laurea Quadriennale in Economia e Commercio</label></td>
                <td><input type="checkbox" name="lqec" value="lqec"></td>
              </tr>
              <tr>
                <td>
    </td>
                <td><label>Laurea Quadriennale in Scienze Statistiche ed Economiche</label></td>
                <td><input type="checkbox" name="lqsse" value="lqsse"></td>
              </tr>
              
              <tr>
                <td>[b]Disciplina*[/b]</td>
                <td colspan="2"><input type="text" name="disciplina" size="30"></td>
              </tr>
              <tr>
                <td>[b]Dipartimento di appartenenza[/b]</td>
                <td colspan="2"><label>
                  <select name="dipartimenti">
                    <option value="nessuno">Nessun dipartimento</option>
                    <option value="statistica">Scienze Statistiche</option>
                    <option value="economia">Scienze Economiche</option>
                    <option value="aziendale">Studi Aziendali e Giusprivatistici</option>
                    <option value="merceologia">Scienze Geografiche e Merceologiche</option>
                    <option value="storia">Studi Europei Giuspubblicistici e Storico-Economici</option>
                    <option value="bioetica">Bioetica</option>
                    <option value="lingue">Area linguistica</option>
                  </select>
                </label></td>
              </tr>
              <tr> 
                <td>[b]Allegare file (sono permessi solo i file con estensione .doc) *[/b]</td>
                <td colspan="2">
                  <input type="hidden" name="MAX_FILE_SIZE" value="1020000400"> 
                  <input name="thefile" type="file" SIZE="35">
                </td>
              </tr>
              <tr> 
                <td>[b]Commenti o note eventuali[/b]</td>
                <td colspan="2"> 
                  <textarea name="commento" wrap="VIRTUAL" cols="30" rows="5"></textarea>
                </td>
              </tr>
              <tr> 
                <td colspan="3">
                  <div align="center">
                    <input type="hidden" name="op" id="op" value="invio" >
                    <input type="submit" name="Submit" value="Invia">
                    <input type="reset" name="Submit2" value="Reimposta">
                  </div>
                </td>
              </tr>
            </table>
          </form>
          

    <font size="1">I campi con l'asterisco sono obbligatori.</font></p>
          

    [url="destroy.php"]Logoff[/url]<font size="1">

            <?
    }
    ?> 
            </font>      </p>
    </table>
        
              </td> 
      </tr> 
            
      </tr> 
     </table>
    ma la mail risulta inviata senza che in realtà arrivi nulla!!!!

    Ho messo come è possibile vedere un
    Codice PHP:
    error_reporting(E_ALL); 
    ma ottengo solo delle notice tra cui:
    Notice: Undefined index: op in /home/web/virtual/economia/areadocenti/formprogrammi_content.php on line 56

    ma che vuol dire? Ho provato a richiamare la variabile in tutti i modi :master:

    ma la mail risulta inviata senza che in realtà arrivi nulla!!!!
    Eccoti!

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.