prova17 Posted October 22, 2015 Share Posted October 22, 2015 Good morning! I have an html form where people should insert the information and then send 2 attachments to a specific email. The following code works but in the attachment of the email I find the name like this --> /tmp/phpJih9x2. Somebody could help me? Following I attach the HTML and PHP file! THANKS HTML <form id="form1" name="form1" method="post" action="email2.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> PHP <?php $allegato = $_FILES['allegato']['tmp_name']; $allegato_type = $_FILES['allegato']['type']; $allegato_name = $_FILES['allegato']['name']; $allegato2 = $_FILES['allegato2']['tmp_name']; $allegato2_type = $_FILES['allegato2']['type']; $allegato2_name = $_FILES['allegato2']['name']; $email = $_POST['email']; $nome = $_POST['nome']; $cognome = $_POST['cognome']; $telefono = $_POST['telefono']; mail_attachment("myemail@mysite.com","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 ?> Quote Link to comment Share on other sites More sharing options...
Stefany93 Posted October 23, 2015 Share Posted October 23, 2015 Don't bother sending attachments with the native mail() function, use PHPMailer. http://www.sitepoint.com/sending-emails-php-phpmailer/ 2 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.