...

View Full Version : email with txt post and file joined



nantais44
01-26-2007, 10:13 AM
Hello all,

i try to do a script with possibility to upload a file and send an email with the file attached in the body.
i do this, the file is well uploaded, but i dont succeed to send the email with the file attached
i hope someone could help me
thanks


<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<TITLE>
<?php

echo "Message</TITLE>
<meta http-equiv=\"Content-Language\" content=\"fr\">
</HEAD>
<BODY bgcolor=\"#000000\">";
$repertoireDestination = "";
$nomDestination = $_FILES["fic"]["name"];

// Pour raison de sécurité nous ajouterons aux fichiers
// portant une extension .php .php3, l'extension .txt
if (eregi(".php", $nomDestination)) {
$nomDestination .= ".txt";
}

if (is_uploaded_file($_FILES["fic"]["tmp_name"])) {
if (rename($_FILES["fic"]["tmp_name"],
$repertoireDestination.$nomDestination)) {
echo "Le fichier temporaire ".$_FILES["fic"]["tmp_name"].
" a été déplacé vers ".$repertoireDestination.$nomDestination;
} else {
echo "Le déplacement du fichier temporaire a échoué".
" vérifiez l'existence du répertoire ".$repertoireDestination;
}
} else {
echo "Le fichier n'a pas été uploadé (trop gros ?)";
}

if ($email !="" && $email2 !="" && $nom !="" && $nom2 !="")
{
$boundary = "-----=".md5(uniqid(rand()));
$header = "MIME-Version: 1.0\r\n";
$header .= "Content-Type: multipart/mixed; boundary=\"$boundary\"\r\n";
$header .= "\r\n";
$body = stripslashes($body);
$msg = "Je vous informe que ceci est un message au format MIME 1.0 multipart/mixed.\r\n";
$msg .= "--$boundary\r\n";
$msg .= "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n";
$msg .= "Content-Transfer-Encoding:8bit\r\n";
$msg .= "\r\n";
$msg .= "Bonjour $nom,";
$msg .= "\r\n\r\n";
$msg .= "\r\n\r\n";
$msg .= "$body";
$msg .= "\r\n\r\n";
$f_serv=$_FILES['fic']['tmp_name']; // Fichier sur le serveur
$f_name=$_FILES['fic']['.name']; // Fichier envoyé
$f_size=intval($_FILES['fic']['size']); // Taille du fichier
$f_type=$_FILES['fic']['type']; // Type du fichier

if(@is_uploaded_file($f_serv))
{

$fp = fopen($f_name, "rb"); // b c'est pour les windowsiens
$attachment = fread($fp, filesize($f_name));
fclose($fp);
$attachment = chunk_split(base64_encode($attachment));
$msg .= "--$boundary\r\n";
$msg .= "Content-Type: image/gif; name=\"$f_name\"\r\n";
$msg .= "Content-Transfer-Encoding: base64\r\n";
$msg .= "Content-Disposition: inline; filename=\"$f_name\"\r\n";
$msg .= "\r\n";
$msg .= $attachment . "\r\n";
$msg .= "\r\n\r\n";
$msg .= "--$boundary--\r\n";
}

$destinataire = "$email";

mail($destinataire, "test", $msg,
"Reply-to: $email2\r\nFrom: pouemes@free.fr\r\n".$header);

echo "<br><br><br><br><br><B><FONT SIZE=\"2\" COLOR=\"white\" face=\"verdana\"><CENTER>Votre message a été envoyé à :<br><br>$email<br><br><br>Merci beaucoup,<br><br> webmaster du site htt://monsite.com<br><br><br><br><A HREF=\"Javascript:history.go(-1)\"><FONT SIZE=\"2\" COLOR=\"white\" face=\"verdana\">Revenir à la page précédente</font></A></CENTER></FONT></B>";
exit;
}
echo "<CENTER><br><img src=\"../ban.gif\" width=\"468\" height=\"80\" border=\"0\" alt=\"\">
<FONT SIZE=\"3\" COLOR=\"#ffffff\"><br><br><br><br><B>Message";
?> à un ami</B></FONT></CENTER><br>
<CENTER><FONT SIZE="1" face="verdana" COLOR="white"><B>Tous les champs sont obligatoires sauf le message</B></FONT></CENTER>
<form enctype="multipart/form-data" action="monscriptetupload.php" method="post">
<div align="center">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Transfère le fichier
<input type="file" name="fic" />
<input type="submit" />
</div>
</form>

<form action="<?PHP $PHP_SELF ?>" method="post">
<div align="center"><center>
<table width="500" border="0" align="center">
<tr><td width="200"><CENTER><B><FONT SIZE="2" COLOR="white" face="arial">Votre email</FONT></B></CENTER></td>
<td width="300"><input type="text" name="email2" size="40"></td></tr>
<tr><td width="200"><CENTER><B><FONT SIZE="2" COLOR="white" face="arial">Votre nom</FONT></B></CENTER></td>
<td width="300"><input type="text" name="nom2" size="40"></td></tr>
<tr><td width="200"><CENTER><B><FONT SIZE="2" COLOR="white" face="arial">Email du destinataire</FONT></B></CENTER></td>
<td width="300"><input type="text" name="email" size="40"></td></tr>
<tr><td width="200"><CENTER><B><FONT SIZE="2" COLOR="white" face="arial">Nom du destinataire</FONT></B></CENTER></td>
<td width="300"><input type="text" name="nom" size="40"></td></tr>
<tr><td width="200"><CENTER><B><FONT SIZE="2" COLOR="white" face="arial">Ajouter, remplacer<br>Par votre message</FONT></B></CENTER></td>
<td width="300"><textarea name="body" rows="4" cols="34">
voici mon message
Bla Bla Bla
Bla Bla Bla
Bla Bla Bla
</textarea></td></tr>
<tr><td colspan="2"><CENTER></CENTER></td></tr>
<tr><td colspan="2"><CENTER><br><input type="submit" value="Cliquez-ici pour envoyer votre message"></CENTER></td></tr>
</table>
</center>
</div>
</form>
</BODY>
</html>

gunman
01-27-2007, 07:48 AM
There are already a lot of mail classes online just use one of them it would be easier for you. Good Luck

nantais44
01-28-2007, 03:41 PM
thanks gunman but i dont succeed to find a script on internet were people can put a message there email email destination and upload there joined file
i think my script above is not fare to work



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum