salve

sto usando drupal per inviare mail con attach

non mi funziona!!!

posto la porzione di codice che si occupa di gestire la mail con allegati codice:

POTETE AIUTARMI a capire cosa non va?

GRAZIE

###################à
function _contact_attach_process_attachments($message) {
$return_message = array();

// Loop through each possible attachment.
for ($i = 1; $i <= variable_get('contact_attach_number', '3'); $i++) {
if ($file = file_save_upload('contact_attach_'. $i)) {
// Check to see if the attachment exists.
if ($file->filesize > 0) {
// An attachment exists, so save it to an array for later processing.
$files[] = $file;
}
}
}

// If the array cantains something, we have one or more attachments to
// process. If it does not contain anything, we send back an empty $body,
// indicating no attachments exist.
if (!empty($files)) {
// Set initial values.
$body = '';
$return_message = array();
$boundary_id = md5(uniqid(time()));

$message['headers']['Content-Type'] = 'multipart/mixed; boundary="'. $boundary_id .'"';


$body = "\n--$boundary_id\n";
$body .= "Content-Type: text/plain; charset=iso-8859-1; \n"; // sets the mime type
$body .= "Content-Transfer-Encoding: 7bit\n\n";

// Prepare the body:
$body .= implode("\n\n", $message['body']);
$body .= "\n\n\n";

// Add the attachments.
// Loop through each possible attachment.
for ($i = 0; $i < count($files); $i++) {
// Process the attachment.
$body .= "--$boundary_id\n";
$body .= _contact_attach_add_attachment($files[$i]);
$body .= "\n\n";
}

$body .= "--$boundary_id--\n";

$return_message['headers'] = $message['headers'];
die(var_dump($return_message['headers']));
$return_message['body'] = $body;
//die($return_message['headers']);
}

return $return_message;
} // End of _contact_attach_process_attachments().



/**
* Add an attachment to the message body.
*
* @param file
* An attachment to add to the message.
* @return
* The processed attachment, ready for appending to the message.
*/
function _contact_attach_add_attachment($file) {
//$attachment = "Content-Type: ". $file->filemime ."; name=\"". basename($file->filename) ."\"\n";
$attachment .= "Content-Disposition: attachment; filename=\"". basename($file->filename) ."\"\n";
$attachment .= "Content-Transfer-Encoding: base64\n\n";
if (file_exists($file->filepath)) {
$attachment .= chunk_split(base64_encode(file_get_contents($file->filepath)));
}
else {
$attachment .= chunk_split(base64_encode(file_get_contents(file_d irectory_temp() .'/'. $file->filename)));
}
//die($attachment);
return $attachment;
} // End of _contact_attach_add_attachment().