Salve a tutti, sono riuscito ad inviare una mail con oggetto e testo verso un destinatario. Ora manca solo l inserimento dell allegato che carico in un form. Posto il codice
Codice PHP:
$to = "info@danielebarisano.it"; $htmlContent1='<html> <body><div style="width:600px;margin:0 auto;padding:30px 20px;border-radius:10px; border:1px solid yellow;"> <center style="font:18px calibri;color:#333; background:yellow;margin:-30px -17px 0px -17px;">Prova</center> <br/><br/> <strong style="margin: 0 100px 0 30px;font-size:14px; font-family: sans-serif;"> Nome: <strong style=" font-size:16px; color:#BAAC8F;">'.$name.'</strong> <br> <strong style="margin: 0 100px 0 30px;font-size:14px; font-family: sans-serif;"> Email: <strong style=" font-size:16px; color:#BAAC8F;">'.$email.'</strong> <br> <strong style="margin: 0 100px 0 30px;font-size:14px; font-family: sans-serif;"> File: <strong style=" font-size:16px; color:#BAAC8F;">'.$uploadedFile.'</strong> <br> </div> </body> </html>'; // Set content-type for sending HTML email /*$headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; $headers .= "From:$email";*/
$file_name = $_FILES['file']['name']; $temp_name = $_FILES['file']['tmp_name']; $file_type = $_FILES['file']['type']; $base = basename($file_name); $extension = substr($base, strlen($base)-4, strlen($base)); //only these file types will be allowed $allowed_extensions = array(".doc", "docx", ".pdf", ".zip", ".png",".jpg"); //check that this file type is allowed if(in_array($extension,$allowed_extensions)) { //mail essentials $from = $email; $to = "info@danielebarisano.it"; //things u need $file = $temp_name; $content = chunk_split(base64_encode(file_get_contents($file))); $uid = md5(uniqid(time())); //unique identifier //standard mail headers $header = "From: ".$email."\r\n"; $header .= "Reply-To: ".$replyto. "\r\n"; $header .= "MIME-Version: 1.0\r\n"; //declare multiple kinds of email (plain text + attch) $header .="Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n"; $header .="This is a multi-part message in MIME format.\r\n"; //plain txt part $header .= "--".$uid."\r\n"; $header .= "Content-type:text/plain; charset=iso-8859-1\r\n"; $header .= "Content-Transfer-Encoding: 7bit\r\n"; $header .= $message. "\r\n"; //attch part $header .= "--".$uid."\r\n"; $header .= "Content-Type: ".$file_type."; name=\"".$file_name."\"\r\n"; $header .= "Content-Transfer-Encoding: base64\r\n"; $header .= "Content-Disposition: attachment; filename=\"".$file_name."\"\r\n"; $header .= $content."\r\n"; //chucked up 64 encoded attch //sending the mail - message is not here, but in the header in a multi part if(mail($to, 'Inserimento', $htmlContent1, $header)) { echo "success"; }else { echo "fail"; } }else { echo "file type not allowed"; }
codice HTML:
<form id="fupForm" action="submit.php" method="POST" enctype="multipart/form-data"> <div class="form-group"> <label for="name">Name</label> <input type="text" class="form-control" id="name" name="name" placeholder="Enter name" required /> </div> <div class="form-group"> <label for="email">Email</label> <input type="email" class="form-control" id="email" name="email" placeholder="Enter email" required /> </div> <div class="form-group"> <label for="file">File</label> <input type="file" class="form-control" id="file" name="file" required /> </div> <input type="submit" name="submit" class="btn btn-success submitBtn" value="SUBMIT"/> </form>
L errore sulla pagina PHP è questo file_get_contents(/tmp/phpGmaZM8): failed to open stream: No such file or directory e avviene in questa riga:
Codice PHP:
$content = chunk_split(base64_encode(file_get_contents($file)));
Chi sa darmi una mano?