I have use a very close version of this script in many web site but this one doesn't work. It's a mailing list with file attached.
The file is indeed on the server but the image/file is not interpreted correctly.
Any suggestion will be welcomed
Code:
// I drop the file on the server
if(!empty($_FILES['fichier'])){
$nom = substr($_FILES['fichier']['name'], strripos($_FILES['fichier']['name'], '.'));
$extension= substr($nom, 1, 3);
$connection = ftp_connect('cld-charlevoix.org') or die("connection impossible");
ftp_login($connection, $user, $password) or die("user erreur ou mot de passe");
ftp_put($connection,("/public_html/admin/attachement/".$_FILES['fichier']['name']),$fichier,FTP_BINARY) or die("le transfert marche pas");
ftp_close($connection);
echo "go";
}
// then i create the script for the mailing
if(isset($_POST['groupe'])){
//---------------------------------------------------------- ramasse le texte et le titre
$sql_texte2=mysql_query("SELECT * FROM texte WHERE id_texte='18'");
$ligne_texte2=mysql_fetch_array($sql_texte2);
$titre_texte2=$ligne_texte2['titre']; // le titre du message
//------------------------------------------
foreach($_POST['groupe'] as $lesgroupes) {
if($_POST['groupe'][0] !='tous'){
$sql_listeenvoi=mysql_query("SELECT * FROM listeenvoi where groupe='".$lesgroupes."' and actif='oui' ORDER BY courriel ASC");
}
else{
$sql_listeenvoi=mysql_query("SELECT * FROM listeenvoi where actif='oui' ORDER BY courriel ASC");
}
$i=1;
while($ligne_listeenvoi=mysql_fetch_array($sql_listeenvoi)){
$to = "".$ligne_listeenvoi['courriel']."";
//------------------------------------------
$sujet = $titre_texte2;
$delimiteur=md5(uniqid(rand()));
$entete = "MIME-version: 1.0\n";
$entete .= "From:info@cld-charlevoix.org\n";
$entete .= "Content-type: multipart/mixed; boundary=".$delimiteur." \n ";
$entete .= " \n";
$sujet = $titre_texte;
$message ="--".$delimiteur."\n";
$message .= "Content-type: text/html; charset= \"iso-8859-1\"\n";
$message .= "Content-Transfer-Encoding:8bit\n";
$message .= "\n";
$message .="Hello";
$message .= "\n";
$message .="--".$delimiteur." \n";
if(!empty($_FILES['fichier']['name'])){
$fichier ="attachement/".$_FILES['fichier']['name']."";
$attache = file_get_contents($fichier);
$attache = chunk_split(base64_encode($attache));
$message .="--".$delimiteur." \n";
$message .="Content-Type: application/".$extension."; name=".$fichier." \n";
$message .="Content-Transfer-Encoding: Base64\n";
$message .="Content-Disposition: inline; filename=".$fichier." \n";
$message .= "\n";
$message .= $attache." \n";
$message .= "\n";
$message .="--".$delimiteur." \n";
}
mail($to,$sujet,$message,$entete, "-flamuse@lamuse.com");
}}}
echo "$to<br>";
?>
The file is indeed on the server but the image/file is not interpreted correctly.
Any suggestion will be welcomed