Ho creato dei metodi x una classe x l'invio di mail.. In caso di necessità devo avere la possibilità di inserire un file di testo (e questo funziona) ma anche allegare un immagine. Ho scritto questo metodo ma nn va:
codice:
function sendmailgarl($dest, $mittente, $reply, $titolo, $pathfile, $filename, $inFILE=false){
$intestazioni = $this->createintest($mittente, $reply, $titolo);
$body_top = $this->getbodytop();
$msg_body = $body_top;
// gestisco il primo allegato
$filez = fopen($pathfile, "r");
$contents = fread($filez, filesize($pathfile));
$encoded_attach = chunk_split(base64_encode($contents));
fclose($filez);
// allega il file di testo
$msg_body .= "\n\n--Message-Boundary\n";
$msg_body .= "Content-type: ".$this->getfiletype('text')."; name=\"$filename\"\n";
$msg_body .= "Content-Transfer-Encoding: BASE64\n";
$msg_body .= "Content-disposition: attachment; filename=\"$filename\"\n\n";
$msg_body .= "$encoded_attach\n";
$msg_body .= "--Message-Boundary--\n";
// se ho inserito l'allegato immagine allora cerco di inviarla con la mail
if($inFILE){
// allega il file di testo
$msg_body .= "\n\n--Message-Boundary\n";
$msg_body .= "Content-type: ".$this->getfiletype('image')."; name=\"$filename\"\n";
$msg_body .= "Content-Transfer-Encoding: BASE64\n";
$msg_body .= "Content-disposition: attachment; filename=\"$filename\"\n\n";
$msg_body .= $inFILE['image']['tmp_name']."\n";
$msg_body .= "--Message-Boundary--\n";
}
if(!(@mail($dest,"Posizione oggetto",$msg_body, $intestazioni))){
return 0;
}
return 1;
}
function createintest($mittente, $reply, $titolo){
return "From: $mittente\nReply-To: $reply\nX-Mailer: Sismail Web Email Interface\nMIME-version: 1.0\nContent-type: multipart/mixed;\n boundary=\"Message-Boundary\"\nContent-transfer-encoding: 7BIT\nX-attachments: $titolo";
}
Riuscite darmi una mano su come mai non funzioni???
Ciao e grazie