Visualizzazione dei risultati da 1 a 2 su 2

Visualizzazione discussione

  1. #1
    Utente di HTML.it
    Registrato dal
    Jun 2010
    Messaggi
    9

    Send email with multiple attachments in PHP

    Good morning!

    I have an html file where people should insert the information and then send to a specific email with 2 attachments. The following code works but attach 2 files to 0KB and I receive the following error.

    Warning: file_get_contents(File1-test.jpg): failed to open stream: No such file or directory in /web/htdocs/www.mysite.net/home/email.php on line 26 Warning: file_get_contents(File2-test.pdf): failed to open stream: No such file or directory in /web/htdocs/www.mysite.net/home/email.php on line 26

    Messaggio spedito correttamente a myemail@mysite.net!


    Somebody could help me?

    THANKS

    My HTML file!

    codice HTML:
    <form id="form1" name="form1" method="post" action="email.php" enctype="multipart/form-data">
    
    <fieldset>
    <legend>Canditatura</legend>
    <label>Nome:</label> <input type="text" placeholder="Inserisci il tuo nome" name="nome"  size="30px" required="true"><br>
    <label>Cognome:</label> <input type="text" placeholder="Inserisci il tuo cognome" name="cognome" size="30px" required="true"><br>
    <label>Email:</label> <input type="email" name="email" placeholder="example@example.it" size="30px" required="true"><br>
    <label>Telefono:</label> <input type="tel" name="telefono" placeholder="+39" size="30px"><br>
    <label>Allegato 1:</label> <input type="file" id="allegato" name="allegato" required="true"><br>
    <label>Allegato 2:</label> <input type="file" id="allegato2" name="allegato2" required="true"><br>
    <br><br>
    <label class="lprivacy"><input type="checkbox" required="true">Accetto normativa sulla Privacy</label><input type="submit" value="Invia Canditatura" name="submit">
    </fieldset>
    </form>


    This is my PHP file (email.php).

    Codice PHP:
    <?php
    $allegato 
    $_FILES['allegato']['name'];
    $allegato2 $_FILES['allegato2']['name'];
    $email $_POST['email'];
    $nome $_POST['nome'];
    $cognome $_POST['cognome'];
    $telefono $_POST['telefono'];
    $files = array();

      
    mail_attachment("myemail@mysite.net","Subject","Nuova canditatuda da <b>$nome $cognome</b>. <br> Telefono: $telefono <br> Email: $email ",array("$allegato","$allegato2"));
      function 
    mail_attachment($to$subject$message$files) {
          
    $headers "From: no-reply@mail.com";
          
    $semi_rand md5(time());
          
    $mime_boundary "==Multipart_Boundary_x{$semi_rand}x";
          
    $headers .= "\nMIME-Version: 1.0\n" "Content-Type: multipart/mixed;\n" " boundary=\"{$mime_boundary}\"";

          
    $message "This is a multi-part message in MIME format.\n\n" "--{$mime_boundary}\n" "Content-Type: text/html; charset=\"iso-8859-1\"\n" "Content-Transfer-Encoding: 7bit\n\n" $message "\n\n";
          
    $message .= "--{$mime_boundary}\n";

          foreach (
    $files as $file) {

            
    $filename end(explode("/",$file));
            
    $data file_get_contents($file);

            
    $data chunk_split(base64_encode($data));

            
    $message .= "Content-Type: {\"application/octet-stream\"};\n" " name=\"$file\"\n" .
              
    "Content-Disposition: attachment;\n" " filename=\"$file\"\n" .
              
    "Content-Transfer-Encoding: base64\n\n" $data "\n\n";
            
    $message .= "--{$mime_boundary}\n";
          }
            echo (@
    mail($to$subject$message$headers)) ? "<p>Messaggio spedito correttamente a $to!</p>" "<p>ERRORE! Messaggio non spedito a $to!</p>";
      } 
    // mail-attachment
    ?>
    Ultima modifica di prova17; 22-10-2015 a 12:11

Tag per questa discussione

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.