Per un sito ho utilizzato un formmail in php che permette di allegare un file.
Il problema che sto stronzo manda la mail con l'allegato, solo che quest'ultimo immancabilmente pesa sempre 0 byte.. cazzo!!!
Ora io sto cercando uno stramaledettissimo formmail che faccia le seguenti cose:
controlli la presenza di testo nel campo "nome cognome";
controlli che la sintassi dell'email sia giusta;
controlli la presenza di testo nel campo "messaggio";
controlli che l'allegato sia delle dimensioni massime prefissate e abbia una delle 2 estensioni permesse.
Sto cercando da parecchio ma non riesco a trovarne uno che risponda alle mie esigenze..
Il codice che usavo è il seguente:
function get_ext($key) { $key=strtolower(substr(strrchr($key, "."), 1)); // Cause there the same right? $key=str_replace("jpeg","jpg",$key); return $key; } function phattach($file,$name) { global $boundary; $fp=fopen($file,"r"); $str=fread($fp, filesize($file)); $str=chunk_split(base64_encode($str)); $message="--".$boundary."\n"; $message.="Content-Type: application/octet-stream; name=\"".$name."\"\n"; //$message.="Content-disposition: attachment\n"; Thanks goes to someone named Chris (I think, it was awhile ago) for his fix below! $message.="Content-disposition: attachment; filename=\"".$name."\"\n"; $message.="Content-Transfer-Encoding: base64\n"; $message.="\n"; $message.="$str\n"; $message.="\n"; return $message; } //Little bit of security from people forging headers. People are mean sometimes <img src='http://www.hwupgrade.org/public/style_emoticons/<#EMO_DIR#>/afraid.gif' class='bbc_emoticon' alt=':paura:' /> function clean($key) { $key=str_replace("\r", "", $key); $key=str_replace("\n", "", $key); $find=array( "/bcc\:/i", "/Content\-Type\:/i", "/Mime\-Type\:/i", "/cc\:/i", "/to\:/i" ); $key=preg_replace($find,"",$key); return $key; } // Safe for register_globals=on =) $error=""; $types=""; $sent_mail=false; // Do some loopy stuff for the valid file types so people can see what types are valid before they try and upload invalid ones. $ext_count=count($allowtypes); $i=0; foreach($allowtypes AS $extension) { //Gets rid of the last comma If($i <= $ext_count-2) { $types .="*.".$extension.", "; } Else { $types .="*.".$extension; } $i++; } unset($i,$ext_count); // why not // If they post the form start the mailin'! If($_POST['submit']==true) { extract($_POST, EXTR_SKIP); // Check the form for errors If(trim($yourname)=="") { $error.="Non hai inserito il tuo nome e cognome. "; } If(trim($youremail)=="") { $error.="Non hai inserito il tuo indirizzo email. "; } Elseif(!eregi("^([a-z0-9_]|\\-|\\.)+@(([a-z0-9_]|\\-)+\\.)+[a-z]{2,4}\$",$youremail)) { $error.="Indirizzo email non valido. "; } If(trim($emailsubject)=="") { $emailsubject=$defaultsubject; } If(trim($yourmessage)=="") { $error.="Non hai inserito un messaggio. "; } // Verify Attachment info If($allowattach > 0) { //Loopish For($i=0; $i <= $allowattach-1; $i++) { If($_FILES['attachment']['name'][$i]) { $ext=get_ext($_FILES['attachment']['name'][$i]); $size=$_FILES['attachment']['size'][$i]; $max_bytes=$max_file_size*1024; //Check if the file type uploaded is a valid file type. If(!in_array($ext, $allowtypes)) { $error.= "Estensione del file allegato non valida: ".$_FILES['attachment']['name'][$i].", puoi allegare solo curriculum in ".$types." Grazie. "; //Check the size of each file } Elseif($size > $max_bytes) { $error.= "Il tuo: ".$_FILES['attachment']['name'][$i]." è troppo grande. Puoi allegare curriculum grandi al massimo ".$max_file_size."kb. "; } } // If Files } // For //Tally the size of all the files uploaded, check if it's over the ammount. $total_size=array_sum($_FILES['attachment']['size']); $max_file_total_bytes=$max_file_total*1024; If($total_size > $max_file_total_bytes) { $error.="Puoi allegare curriculum grandi al massimo ".$max_file_total."kb "; } } // If Allowattach If($error) { $display_message=$error; } Else { If($use_subject_drop AND is_array($subjects) AND is_array($emails)) { $subject_count=count($subjects); $email_count=count($emails); If($subject_count==$email_count) { $myemail=$emails[$emailsubject]; $emailsubject=$subjects[$emailsubject]; } } $boundary=md5(uniqid(time())); //Little bit of security from people forging headers. People are mean sometimes <img src='http://www.hwupgrade.org/public/style_emoticons/<#EMO_DIR#>/asd.gif' class='bbc_emoticon' alt=':asd:' /> $yourname=clean($yourname); $yourmessage=clean($yourmessage); $youremail=clean($youremail); //Headers $headers="From: ".$yourname." <".$youremail.">\n"; $headers.="Reply-To: ".$yourname." <".$youremail.">\n"; $headers.="MIME-Version: 1.0\n"; $headers.="Content-Type: multipart/mixed; boundary=\"".$boundary."\"\n"; $headers.="X-Sender: ".$_SERVER['REMOTE_ADDR']."\n"; $headers.="X-Mailer: PHP/".phpversion()."\n"; $headers.="X-Priority: ".$priority."\n"; $headers.="Return-Path: <".$youremail.">\n"; $headers.="This is a multi-part message in MIME format.\n"; //Message $message = "--".$boundary."\n"; $message.="Content-Type: text/plain; charset=\"iso-8859-1\"\n"; $message.="Content-Transfer-Encoding: quoted-printable\n"; $message.="\n"; $message.="$yourmessage"; $message.="\n"; //Lets attach to something! =) If($allowattach > 0) { For($i=0; $i <= $allowattach-1; $i++) { If($_FILES['attachment']['name'][$i]) { $message.=phattach($_FILES['attachment']['tmp_name'][$i],$_FILES['attachment']['name'][$i]); } } //For } // If // End the message $message.="--".$boundary."--\n"; // Send the completed message If(!mail($myemail,$emailsubject,$message,$headers)) { Exit("Attenzione, E' avvenuto un errore. Vi preghiamo di riferire tale errore a cazz'inculononfafigli@mafamaleselopigli Grazie.\n"); } Else { $sent_mail=true; } } // Else } // $_POST
Se qualcuno riesce a spiegarmi perchè sto infame mi manda allegati da 0kb gli dedico una poesia