Ragazzi ho modificato lo script così ma non funziona e non capisco il motivo
codice:
<?php
// Verifichiamo di avere l'oggetto e il testo dalla form
if (isset($_POST['subject']) && isset($_POST['text'])) {
if (trim($_POST['subject'])!='' && trim($_POST['text'])!='') {
/* Abbiamo tutto quello che ci serve, ora con una query prendiamo
tutti gli indirizzi dal db */
if($_POST['localita']=='Tutte'){
$sql = "SELECT email FROM newsleter";
$res = mysql_query($sql);
} elseif ($_POST['citta']=='') {
$sql = "SELECT email FROM newsleter WHERE localita= '".$_POST['localita']."'";
$res = mysql_query($sql);
} else {
$sql = "SELECT email FROM newsleter WHERE localita= '".$_POST['localita']."' AND citta ='".$_POST['citta']."'";
$res = mysql_query($sql);
}
$subject = stripslashes($_POST['subject']);
$text = stripslashes($_POST['text']);
// Obtain file upload vars
$attachment= $_FILES['attachment']['tmp_name'];
$attachment_type = $_FILES['attachment']['type'];
$attachment_name = $_FILES['attachment']['name'];
$headers = "From: <email@libero.it>\r\n";
if (is_uploaded_file($attachment)) {
// Read the file to be attached ('rb' = read binary)
$file = fopen($attachment,'rb');
$data = fread($file,filesize($attachment));
fclose($file);
// Generate a boundary string
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// Add the headers for a file attachment
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/html;\n" .
" boundary=\"{$mime_boundary}\"";
/* $headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";*/
$headers .= "Content-Type: multipart/alternative;\n";
$headers .= " boundary=\"$boundary2\";\n\n";
// Add a multipart boundary above the plain message
$text .= "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$text . "\n\n";
// Base64 encode the file data
$data = chunk_split(base64_encode($data));
// Add file attachment to the message
$text .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
}
// Send the message
/* Cicliamo il risultato della query e assegnamo
l'indirizzo e-mail alla variabile $to */
while (list($to) = mysql_fetch_row($res)) {
/* e ora inviamo la news */
mail($to, $subject, $text, $headers); }
echo "<script>";
echo "alert('Newsletter inviata!');";
echo "</script>";
} else {
echo "<script>";
echo "alert('Tutti i campi sono obbligatori!');";
echo "</script>";
}
} else {
/*
Il contenuto della form non è arrivato, questo può succedere
se si accede a questa pagina direttamente senza fare il
*/
}
?>