J'ai passé 2aprèmes entieres a chercher du code qui créerait un formulaire qui m'enverrait le contenu d'une zone texte, et une pièce jointe.
Or, j'ai réussi a ce que l'envoi du mail se fasse, mais la pièce jointe bloque...
D'un coté, j'ai le formulaire et son php qui envoie correctement le mail (avec message) et de l'autre coté, j'ai un autre formulaire et son php qui envoie un tas d'info mais surtout une pièce jointe, et ca marche.
J'ai essayé d'integrer pas a pas la mise en forme de mon propre formulaire dans celui qui fonctionne avec la pièce jointe, mais rien a en tirer... J'ai fait des centaines de tests pour reperer d'ou venaient les erreurs, et je suis tombé sur des constatation désolantes... Exemple : quand je déclare un champ du formulaire en type="hidden", le mail ne s'envoie plus... Donc, vous restez mon seul espoir!
Je précise que j'ai créer mon formulaire perso avec Dreamweaver 8.
Je suis conscient qu'il y a surement du code inutile dans tout mon charabia mais j'ai préféré ne pas enlever des trucs qui pourraient être vital...
Voici le formulaire de mon mail qui marche answer.php :
(Désolé de mettre la déclaration de chaque calque, mais je préfère ne rien laisser au hasard...)
Citation
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Answer By Tiss</title>
<style type="text/css">
<!--
textarea {
color:white;
font-family:cruiser;
font-size:18px;
padding:1cm;
}
body,td,th {
font-family: Impact;
font-size: 24px;
color: #FFFFFF;
background-image: url(berserk.jpg);
}
body {
background-color: #000000;
background-image: url();
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
#Layer1 {
position:absolute;
width:200px;
height:115px;
z-index:1;
left: 203px;
top: 89px;
}
#Layer2 {
position:absolute;
width:477px;
height:528px;
z-index:2;
left: 20px;
top: 63px;
visibility: visible;
}
#Layer3 {
position:absolute;
width:200px;
height:115px;
z-index:1;
left: 17px;
top: 84px;
visibility: visible;
}
-->
</style>
<script type="text/javascript">
<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->
</script>
</head>
<body>
<div id="Layer2">
<form method="post" action="mail.php">
<p>
<input type="hidden" name="votremail" value="NomFixeDeLExpediteur@aol.com"/>
<!-- Valeur par défaut de l'objet du mail -->
<input type="hidden" name="objet" value="Le Tiss a répondu!" />
</p>
<p>
<textarea cols="54" rows="16" style="background-image: url(berserk.jpg)" name="message"></textarea>
</p>
<p>
<input name="attach" type="file" size="16" maxlength="5000000"/>
</p>
<p>
<input type="submit" value="Envoyer" />
</p>
</form>
</div>
</div>
<div id="Layer3">
<center>
<table width="1024" height="768" border="3" bordercolor="#FFFFFF">
<tr>
<td width="954" height="70"> </td>
</tr>
</table>
</center>
</div>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Answer By Tiss</title>
<style type="text/css">
<!--
textarea {
color:white;
font-family:cruiser;
font-size:18px;
padding:1cm;
}
body,td,th {
font-family: Impact;
font-size: 24px;
color: #FFFFFF;
background-image: url(berserk.jpg);
}
body {
background-color: #000000;
background-image: url();
margin-left: 0px;
margin-top: 0px;
margin-right: 0px;
margin-bottom: 0px;
}
#Layer1 {
position:absolute;
width:200px;
height:115px;
z-index:1;
left: 203px;
top: 89px;
}
#Layer2 {
position:absolute;
width:477px;
height:528px;
z-index:2;
left: 20px;
top: 63px;
visibility: visible;
}
#Layer3 {
position:absolute;
width:200px;
height:115px;
z-index:1;
left: 17px;
top: 84px;
visibility: visible;
}
-->
</style>
<script type="text/javascript">
<!--
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->
</script>
</head>
<body>
<div id="Layer2">
<form method="post" action="mail.php">
<p>
<input type="hidden" name="votremail" value="NomFixeDeLExpediteur@aol.com"/>
<!-- Valeur par défaut de l'objet du mail -->
<input type="hidden" name="objet" value="Le Tiss a répondu!" />
</p>
<p>
<textarea cols="54" rows="16" style="background-image: url(berserk.jpg)" name="message"></textarea>
</p>
<p>
<input name="attach" type="file" size="16" maxlength="5000000"/>
</p>
<p>
<input type="submit" value="Envoyer" />
</p>
</form>
</div>
</div>
<div id="Layer3">
<center>
<table width="1024" height="768" border="3" bordercolor="#FFFFFF">
<tr>
<td width="954" height="70"> </td>
</tr>
</table>
</center>
</div>
</body>
</html>
Citation
<?php
// La variable $verif, va nous permettre d'analyser si la sémantique de l'email est bonne
$verif="!^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]{2,}\.[a-zA-Z]{2,4}$!";
// On assigne et protége nos variables
$votremail=$_POST["votremail"];
$from=htmlentities("From: ".$votremail);
$message=stripslashes(htmlentities($_POST["message"]));
// On met ici notre email
$destinataire="MonNom@aol.com";
/* On place le sujet du message qui ici sera toujours le même
puisque dans la partie Html on l'a mis en caché grace au type="hidden"
avec comme valeur "Vous avez un nouveau message" */
$objet=$_POST['objet'];
// C'est bon on est OK, vérifions si l'email est valide, grâce à notre sympathique REGEX
if(!preg_match($verif,$votremail))
{
echo "Votre email n'est pas valide";
}
// On verifie si il y a un message
elseif (trim($message)=="")
{
echo "Y'en a marre des messages vides !";
}
// Si tout est OK on envoie l'email
else
{
mail($destinataire,$objet,$message,$from);
header("Location: http://nomdedomaine.ifrance.com");
}
?>
// La variable $verif, va nous permettre d'analyser si la sémantique de l'email est bonne
$verif="!^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]{2,}\.[a-zA-Z]{2,4}$!";
// On assigne et protége nos variables
$votremail=$_POST["votremail"];
$from=htmlentities("From: ".$votremail);
$message=stripslashes(htmlentities($_POST["message"]));
// On met ici notre email
$destinataire="MonNom@aol.com";
/* On place le sujet du message qui ici sera toujours le même
puisque dans la partie Html on l'a mis en caché grace au type="hidden"
$objet=$_POST['objet'];
// C'est bon on est OK, vérifions si l'email est valide, grâce à notre sympathique REGEX
if(!preg_match($verif,$votremail))
{
echo "Votre email n'est pas valide";
}
// On verifie si il y a un message
elseif (trim($message)=="")
{
echo "Y'en a marre des messages vides !";
}
// Si tout est OK on envoie l'email
else
{
mail($destinataire,$objet,$message,$from);
header("Location: http://nomdedomaine.ifrance.com");
}
?>
Et voici le formulaire glané sur le net contact.php :
Citation
<form method=POST action="formmail.php" enctype="multipart/form-data">
Adresse : <br><input name="adresse" size=40 value=""><br>
CC : <br><input name="cc" size=40 value=""><br>
BCC : <br><input name="bcc" size=40 value=""><br>
Sujet : <br><input name="subject" size=40 value=""><br>
Message : <br>
<Textarea name="msg" cols=40 rows=10 WRAP=HARD>
</TextArea><br>
Fichiers : <br>
<input type=file size=40 name="attach"><br><br>
<center><input type=submit value="Envoyer"></center>
<input type=hidden name="message" value=1>
</form>
Adresse : <br><input name="adresse" size=40 value=""><br>
CC : <br><input name="cc" size=40 value=""><br>
BCC : <br><input name="bcc" size=40 value=""><br>
Sujet : <br><input name="subject" size=40 value=""><br>
Message : <br>
<Textarea name="msg" cols=40 rows=10 WRAP=HARD>
</TextArea><br>
Fichiers : <br>
<input type=file size=40 name="attach"><br><br>
<center><input type=submit value="Envoyer"></center>
<input type=hidden name="message" value=1>
</form>
Citation
<?
$headers = "From: Votre Nom <monnom@mondomaine.com>\n";
$headers .= "X-Sender: <monnom@mondomaine.com>\n";
$headers .= "X-Mailer: PHP\n";
$headers .= "X-Priority: 3\n";
$headers .= "Return-Path: <monnom@mondomaine.com>\n";
$headers .= "cc:".$cc."\n";
$headers .= "bcc:".$bcc."\n";
if (is_uploaded_file($attach)) {
$file = fopen($attach, "r");
$contents = fread($file, $attach_size);
$encoded_attach = chunk_split(base64_encode($contents));
fclose($file);
$headers .= "MIME-version: 1.0\n";
$headers .= "Content-type: multipart/mixed; ";
$headers .= "boundary=\"Message-Boundary\"\n";
$headers .= "Content-transfer-encoding: 7BIT\n";
$body_top = "--Message-Boundary\n";
$body_top .= "Content-type: text/plain; charset=US-ASCII\n";
$body_top .= "Content-transfer-encoding: 7BIT\n";
$body_top .= "Content-description: Mail message body\n\n";
$msg_cpl = $body_top.stripslashes($msg);
$msg_cpl .= "\n\n--Message-Boundary\n";
$msg_cpl .= "Content-type: $attach_type; name=\"$attach_name\"\n";
$msg_cpl .= "Content-Transfer-Encoding: BASE64\n";
$msg_cpl .= "Content-disposition: attachment; filename=\"$attach_name\"\n\n";
$msg_cpl .= "$encoded_attach\n";
$msg_cpl .= "--Message-Boundary--\n";
}
if (mail ("$adresse","".stripslashes($subject)."","$msg_cpl",$headers)) {
echo ("<center><font color=green>Mail envoyé</font></center>");
}
?>
$headers = "From: Votre Nom <monnom@mondomaine.com>\n";
$headers .= "X-Sender: <monnom@mondomaine.com>\n";
$headers .= "X-Mailer: PHP\n";
$headers .= "X-Priority: 3\n";
$headers .= "Return-Path: <monnom@mondomaine.com>\n";
$headers .= "cc:".$cc."\n";
$headers .= "bcc:".$bcc."\n";
if (is_uploaded_file($attach)) {
$file = fopen($attach, "r");
$contents = fread($file, $attach_size);
$encoded_attach = chunk_split(base64_encode($contents));
fclose($file);
$headers .= "MIME-version: 1.0\n";
$headers .= "Content-type: multipart/mixed; ";
$headers .= "boundary=\"Message-Boundary\"\n";
$headers .= "Content-transfer-encoding: 7BIT\n";
$body_top = "--Message-Boundary\n";
$body_top .= "Content-type: text/plain; charset=US-ASCII\n";
$body_top .= "Content-transfer-encoding: 7BIT\n";
$body_top .= "Content-description: Mail message body\n\n";
$msg_cpl = $body_top.stripslashes($msg);
$msg_cpl .= "\n\n--Message-Boundary\n";
$msg_cpl .= "Content-type: $attach_type; name=\"$attach_name\"\n";
$msg_cpl .= "Content-Transfer-Encoding: BASE64\n";
$msg_cpl .= "Content-disposition: attachment; filename=\"$attach_name\"\n\n";
$msg_cpl .= "$encoded_attach\n";
$msg_cpl .= "--Message-Boundary--\n";
}
if (mail ("$adresse","".stripslashes($subject)."","$msg_cpl",$headers)) {
echo ("<center><font color=green>Mail envoyé</font></center>");
}
?>
Et pour finir, voila ce que j'ai essayé d'en faire pour concilier les 2, histoire que ca vous donne une idée de ce que je veux réaliser a la fin, si je n'ai pas été très clair...
J'ai utilisé mon formulaire perso answer.php posté plus haut et voici le morceau de php correspondant :
Citation
<?php
// La variable $verif, va nous permettre d'analyser si la sémantique de l'email est bonne
$verif="!^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]{2,}\.[a-zA-Z]{2,4}$!";
// On assigne et protége nos variables
$votremail=$_POST["votremail"];
$from=htmlentities("From: ".$votremail);
$message=stripslashes(htmlentities($_POST["message"]));
// On met ici notre email
$destinataire="MonNom@aol.com";
/* On place le sujet du message qui ici sera toujours le même
puisque dans la partie Html on l'a mis en caché grace au type="hidden"
avec comme valeur "Vous avez un nouveau message" */
$objet=$_POST['objet'];
if (!is_uploaded_file($attach))
{
mail($destinataire,$objet,$message,$from);
header("Location: http://NomDeDomaine.ifrance.com");
}
elseif (is_uploaded_file($attach)) {
$file = fopen($attach, "r");
$contents = fread($file, $attach_size);
$encoded_attach = chunk_split(base64_encode($contents));
fclose($file);
$headers .= "MIME-version: 1.0\n";
$headers .= "Content-type: multipart/mixed; ";
$headers .= "boundary=\"Message-Boundary\"\n";
$headers .= "Content-transfer-encoding: 7BIT\n";
$body_top = "--Message-Boundary\n";
$body_top .= "Content-type: text/plain; charset=US-ASCII\n";
$body_top .= "Content-transfer-encoding: 7BIT\n";
$body_top .= "Content-description: Mail message body\n\n";
$msg_cpl = stripslashes($message);
$msg_cpl .= "\n\n--Message-Boundary\n";
$msg_cpl .= "Content-type: $attach_type; name=\"$attach_name\"\n";
$msg_cpl .= "Content-Transfer-Encoding: BASE64\n";
$msg_cpl .= "Content-disposition: attachment; filename=\"$attach_name\"\n\n";
$msg_cpl .= "$encoded_attach\n";
$msg_cpl .= "--Message-Boundary--\n";
}
if (mail ($destinataire,$objet,$msg_cpl,$headers)) {
echo ("<center><font color=green>Mail envoyé</font></center>");
}
// C'est bon on est OK, vérifions si l'email est valide, grâce à notre sympathique REGEX
elseif(!preg_match($verif,$votremail))
{
echo "Votre email n'est pas valide";
}
// On verifie si il y a un message
elseif (trim($message)=="")
{
echo "Y'en a marre des messages vides !";
}
?>
// La variable $verif, va nous permettre d'analyser si la sémantique de l'email est bonne
$verif="!^[a-zA-Z0-9._-]+@[a-zA-Z0-9._-]{2,}\.[a-zA-Z]{2,4}$!";
// On assigne et protége nos variables
$votremail=$_POST["votremail"];
$from=htmlentities("From: ".$votremail);
$message=stripslashes(htmlentities($_POST["message"]));
// On met ici notre email
$destinataire="MonNom@aol.com";
/* On place le sujet du message qui ici sera toujours le même
puisque dans la partie Html on l'a mis en caché grace au type="hidden"
$objet=$_POST['objet'];
if (!is_uploaded_file($attach))
{
mail($destinataire,$objet,$message,$from);
header("Location: http://NomDeDomaine.ifrance.com");
}
elseif (is_uploaded_file($attach)) {
$file = fopen($attach, "r");
$contents = fread($file, $attach_size);
$encoded_attach = chunk_split(base64_encode($contents));
fclose($file);
$headers .= "MIME-version: 1.0\n";
$headers .= "Content-type: multipart/mixed; ";
$headers .= "boundary=\"Message-Boundary\"\n";
$headers .= "Content-transfer-encoding: 7BIT\n";
$body_top = "--Message-Boundary\n";
$body_top .= "Content-type: text/plain; charset=US-ASCII\n";
$body_top .= "Content-transfer-encoding: 7BIT\n";
$body_top .= "Content-description: Mail message body\n\n";
$msg_cpl = stripslashes($message);
$msg_cpl .= "\n\n--Message-Boundary\n";
$msg_cpl .= "Content-type: $attach_type; name=\"$attach_name\"\n";
$msg_cpl .= "Content-Transfer-Encoding: BASE64\n";
$msg_cpl .= "Content-disposition: attachment; filename=\"$attach_name\"\n\n";
$msg_cpl .= "$encoded_attach\n";
$msg_cpl .= "--Message-Boundary--\n";
}
if (mail ($destinataire,$objet,$msg_cpl,$headers)) {
echo ("<center><font color=green>Mail envoyé</font></center>");
}
// C'est bon on est OK, vérifions si l'email est valide, grâce à notre sympathique REGEX
elseif(!preg_match($verif,$votremail))
{
echo "Votre email n'est pas valide";
}
// On verifie si il y a un message
elseif (trim($message)=="")
{
echo "Y'en a marre des messages vides !";
}
?>
Merci par avance!

Aide
Commencer un sujet
Ajouter une réponse

Multi-citation






