Se connecter avec
S'enregistrer | Connectez-vous

Probleme de code sur formulaire mail !

Dernière réponse : dans Programmation

Salut à tous,

Voila mon probleme, j'ai fais un code pour soumettre un formulaire par mail.
Mon formulaire HTML se dispose ainsi :

  1. <FORM METHOD="POST" ACTION="formmail.php">
  2. <INPUT TYPE="hidden" NAME="subject" VALUE="formmail">
  3. <P>Indiquez les coordonnées suivantes :</P>
  4. <BLOCKQUOTE>
  5. <TABLE border="0">
  6. <TR>
  7. <TD ALIGN="right">
  8. <EM>Prénom</EM>
  9. </TD>
  10. <TD>
  11. <INPUT TYPE=TEXT NAME="Contact_Prenom" SIZE=25 >
  12. </TD>
  13. </TR>
  14. <TR>
  15. <TD ALIGN="right">
  16. <EM>Nom</EM></TD>
  17. <TD>
  18. <INPUT TYPE=TEXT NAME="Contact_Nom" SIZE=25 ></TD>
  19. </TR>
  20. <TR>
  21. <TD ALIGN="right">
  22. <EM>Titre</EM></TD>
  23. <TD>
  24. <INPUT TYPE=TEXT NAME="Contact_Titre" SIZE=35 ></TD>
  25. </TR>
  26. <TR>
  27. <TD ALIGN="right">
  28. <EM>Adresse</EM></TD>
  29. <TD>
  30. <INPUT TYPE=TEXT NAME="Contact_Adresse" SIZE=35 ></TD>
  31. </TR>
  32. <TR>
  33. <TD ALIGN="right">
  34. <EM>Adresse (suite)</EM></TD>
  35. <TD>
  36. <INPUT TYPE=TEXT NAME="Contact_Adresse2" SIZE=35 ></TD>
  37. </TR>
  38. <TR>
  39. <TD ALIGN="right">
  40. <EM>Ville</EM></TD>
  41. <TD>
  42. <INPUT TYPE=TEXT NAME="Contact_Ville" SIZE=35></TD>
  43. </TR>
  44. <TR>
  45. <TD ALIGN="right">
  46. <EM>Code postal</EM></TD>
  47. <TD>
  48. <INPUT TYPE=TEXT NAME="Contact_CodePostal" SIZE=12 MAXLENGTH=12></TD>
  49. </TR>
  50. <TR>
  51. <TD ALIGN="right">
  52. <EM>Pays</EM></TD>
  53. <TD>
  54. <INPUT TYPE=TEXT NAME="Contact_Pays" SIZE=25></TD>
  55. </TR>
  56. <TR>
  57. <TD ALIGN="right">
  58. <EM>Téléphone bureau</EM></TD>
  59. <TD>
  60. <INPUT TYPE=TEXT NAME="Contact_TelephoneBureau" SIZE=25 MAXLENGTH=25></TD>
  61. </TR>
  62. <TR>
  63. <TD ALIGN="right">
  64. <EM>Téléphone personnel</EM></TD>
  65. <TD>
  66. <INPUT TYPE=TEXT NAME="Contact_TelephoneDomicile" SIZE=25 MAXLENGTH=25></TD>
  67. </TR>
  68. <TR>
  69. <TD ALIGN="right">
  70. <EM>Courrier électronique</EM></TD>
  71. <TD>
  72. <INPUT TYPE=TEXT NAME="Contact_Email" SIZE=25></TD>
  73. </TR>
  74. <TR>
  75. <TD ALIGN="right">
  76. <EM>URL </EM></TD>
  77. <TD>
  78. <INPUT TYPE=TEXT NAME="Contact_URL " value="http://" SIZE=25 MAXLENGTH=25></TD>
  79. </TR>
  80. <TR>
  81. <TD>
  82. <EM>Publication de mon nom </EM>
  83. </TD>
  84. <FORM>
  85. <TD align="right">
  86. <font color="red">Oui, je l'accepte </font><INPUT TYPE=RADIO NAME="Contact_accept " VALUE="oui" checked></TD>
  87. </TR>
  88. <TR>
  89. <TD> </TD>
  90. <TD align="right">
  91. <font color="red">Non, je ne l'accepte pas </font><INPUT TYPE=RADIO NAME="Contact_accept " VALUE="non"></TD>
  92. </FORM>
  93. </TR>
  94. <TR>
  95. <TD align="right">
  96. <INPUT NAME="valider" TYPE=SUBMIT VALUE="Envoyer"></TD>
  97. <TD align="right">
  98. <INPUT NAME="annuler" TYPE=RESET VALUE="Effacer le contenu"></TD>
  99. </TR>
  100. </TABLE>
  101. </BLOCKQUOTE>
  102. </FORM>

Voici comment se compose mon formmail.php (entre balise php cela va de soit!) :

  1. $TO = "toto@toto.tom";
  2. $sujet = "Réponse au formulaire d'inscription - news IDI";
  3. $qui_nom = $_POST['Contact_Prenom'];
  4. $qui_prenom = $_POST['Contact_Nom'];
  5. $titre = $_POST['Contact_Titre'];
  6. $adresse1 = $_POST['Contact_Adresse'];
  7. $adresse2 = $_POST['Contact_Adresse2'];
  8. $ville = $_POST['Contact_Ville'];
  9. $codepostal = $_POST['Contact_CodePostal'];
  10. $pays = $_POST['Contact_Pays'];
  11. $telbur = $_POST['Contact_TelephoneBureau'];
  12. $teldom = $_POST['Contact_TelephoneDomicile'];
  13. $siteurl = $_POST['Contact_URL'];
  14. $acceptpubli = $_POST['Contact_accept'];
  15. $refuspubli = $_POST['Contact_accept'];
  16. $quimail = "From : " . $_POST['Contact_Email'] . $TO;
  17.  
  18. if (mail($TO, $sujet, $qui_nom, $qui_prenom, $titre, $adresse1, $adresse2, $ville, $codepostal, $pays, $telbur, $teldom, $siteurl, $acceptpubli, $refuspubli, $quimail))
  19.  
  20. header("Location : index.html");
  21.  
  22. else echo "erreur";


Enfin voici l'erreur soumise par mon navigateur :

  1. Warning: mail() [function.mail]: Nombre de parametres incorrects in /mnt/106/sdb/f/5/m.mahlaoui/idi/formmail.php on line 20


Merci aux âmes sensibles à mon probleme de bien vouloir m'aider tant que faure se peut.

Autres pages sur : probleme code formulaire mail

Lassé par la pub ? Créez un compte
Expert Programmation

Dartyduck> Absoument pas ! la page result.html est imposé seulement si tu passes par le script perl fourni par Free. Mais ce n'est pas du tout obligatoire ! Et dans le cas présent, le code php est tout à fait général, même chez Free ;) 

smoon> Va lire la doc sur le fonction mail() : http://fr.php.net/manual/fr/function.mail.php
Tu verras qu'il faut concaténer tes variables qui doivent constituer le corps du message pour n'en former plus qu'une...

Chapellois a dit :
merci. Qui est ton hébergeur ? Si c'est free, Free impose que la page qui est appelée à la validation du formulaire s'appelle result.html et on ne peut pas faire autrement.


Effectivement je suis chez free.
Même si cette page contient du php je dois la nommer en html ?

Shino-Genin a dit :
Eh ben, c'est pourtant comme ça que ça marche. Donc à refaire et mets l'erreur ici si elle revient :) 


Ceci est le mail que je reçois lorsque je soumets mon formulaire :
(Les adresses mails ont été modifiées, ne pas dire que ça ne peut marcher avec des adresses mail pareil !!!)

  1. This is the mail system at host perso1.free.fr.
  2.  
  3. I'm sorry to have to inform you that your message could not
  4. be delivered to one or more recipients. It's attached below.
  5.  
  6. For further assistance, please send mail to <postmaster>
  7.  
  8. If you do so, please include this problem report. You can
  9. delete your own text from the attached returned message.
  10.  
  11. The mail system
  12.  
  13. <toto@toto.tom>: host mx3.to.tom[65.54.245.72] said: 550 Your
  14. e-mail was rejected for policy reasons on this gateway. Reasons for
  15. rejection may be related to content such as obscene language, graphics, or
  16. spam-like characteristics (or) other reputation problems. For sender
  17. troubleshooting information, please go to <a href="http://postmaster.msn.tom" target="_blank">http://postmaster.msn.tom</a>.
  18. Please note: if you are an end-user please contact your E-mail/Internet
  19. Service Provider for assistance. (in reply to MAIL FROM command)


Voici mon code modifié, comme gentillement demandé :D  :
(Les retours à la ligne ne sont là que pour faire de la place !)

  1. <?php
  2.  
  3. $TO = "toto@toto.tom";
  4. $sujet = "Réponse au formulaire d'inscription - news IDI";
  5. $corps = $_POST['Contact_Prenom']."\n".$_POST['Contact_Nom']."\n".$_POST['Contact_Titre']."\n".
  6. $_POST['Contact_Adresse']."\n".$_POST['Contact_Adresse2']."\n".$_POST['Contact_Ville']."\n".
  7. $_POST['Contact_CodePostal']."\n".$_POST['Contact_Pays']."\n".
  8. $_POST['Contact_TelephoneBureau']."\n".$_POST['Contact_TelephoneDomicile']."\n".
  9. $_POST['Contact_URL']."\n".$_POST['Contact_refus']."\n".$_POST['Contact_accept'];
  10.  
  11. if (mail($TO, $sujet, $corps))
  12.  
  13. header("Location : index.html");
  14.  
  15. else echo "erreur";
  16. ?>

Shino-Genin a dit :
Pour ta variable $corps, essaie plutôt :
  1. $corps = '';
  2. foreach($_POST as $key=>$value)
  3. {
  4. $value = stripslashes($value);
  5. $corps .= "$key : $value\n";
  6. }


Voici le code apres modif :

  1. <?php
  2.  
  3. $sujet = "Réponse au formulaire d'inscription - news IDI";
  4. $corps = $_POST["Contact_Prenom"]."\n".$_POST["Contact_Nom"]."\n".$_POST["Contact_Titre"]
  5. ."\n".$_POST["Contact_Adresse"]."\n".$_POST["Contact_Adresse2"]."\n".$_POST["Contact_Ville"]
  6. ."\n".$_POST["Contact_CodePostal"]."\n".$_POST["Contact_Pays"]."\n".$_POST["Contact_TelephoneBureau"]
  7. ."\n".$_POST["Contact_TelephoneDomicile"]."\n".$_POST["Contact_URL"]."\n".$_POST["Contact_accept"];
  8. foreach($_POST as $key=>$value)
  9. {
  10. $value = stripslashes($value);
  11. $corps .= "$key : $value\n <br>";
  12. }
  13.  
  14.  
  15.  
  16.  
  17.  
  18. $headers ='From: '.$_POST["Contact_Email"]."\n";
  19. $headers .='Reply-To: '.$_POST["Contact_Email"]."\n";
  20. $headers .='Content-Type: text/plain; charset="iso-8859-1"'."\n";
  21. $headers .='Content-Transfer-Encoding: 8bit';
  22.  
  23. $message ="\n".'<html>'."\n".'<head>'."\n".'<title>'."\n".$sujet."\n".'</title>'
  24. ."\n".'</head>'."\n".'<body bgcolor="blue">'."\n".'<font color="yellow" face="Comic Sans Ms">'."\n".'<H1>'."\n".'<br>'.$corps."\n".'</H1>'."\n".'</font>'."\n".'</body>'."\n".'</html>';
  25.  
  26. if(mail("toto@to.tom", $sujet, $message, $headers))
  27. {
  28. header("Location : index.html");
  29. }
  30. else
  31. {
  32. echo 'Le message n\'a pu être envoyé, désolé !!!';
  33. }
  34. ?>


Et voici ce que ca donne en clair :


  1. Le message a été envoyé<br>
  2. <html>
  3. <head>
  4. <title>
  5. Réponse au formulaire d'inscription - news IDI
  6. </title>
  7. </head>
  8. <body bgcolor="blue">
  9. <font color="yellow" face="Comic Sans Ms">
  10. <H1>
  11. <br>toto
  12. titi
  13. titi
  14. ti
  15. tititti
  16. ti
  17. ti
  18. ti
  19. tti
  20. ttti
  21.  
  22. subject : formmail
  23. <br>Contact_Prenom : toto
  24. <br>Contact_Nom : titi
  25. <br>Contact_Titre : titi
  26. <br>Contact_Adresse : ti
  27. <br>Contact_Adresse2 : tititti
  28. <br>Contact_Ville : ti
  29. <br>Contact_CodePostal : ti
  30. <br>Contact_Pays : ti
  31. <br>Contact_TelephoneBureau : tti
  32. <br>Contact_TelephoneDomicile : ttti
  33. <br>Contact_Email : toto@to.to
  34. <br>Contact_URL_ : http://totototototo
  35. <br>Contact_accept_ : oui
  36. <br>valider : Envoyer
  37. <br>
  38.  
  39. </H1>
  40. </font>
  41. </body>
  42. </html>


What else ?
Expert Programmation

Il faut que tu vires ce qu'il y a dans ta variable $corps !

Comme indiqué précédemment tu remplaces $corps = 'toutes tes variables que tu as maintenant' par $corps = '' ; ça sert juste à l'initialiser ;) 

Mon code permet de faire la même chose que ta concaténation manuelle, mais de façon auto, en associant en plus le nom de ta variable postée à sa valeur, histoire de mieux t'y retrouver dans ton mail :) 

Au final, ça donne ça :
  1. <?php
  2. $sujet = "Réponse au formulaire d'inscription - news IDI";
  3. $corps = '';
  4. foreach($_POST as $key=>$value)
  5. {
  6. $value = stripslashes($value);
  7. $corps .= "$key : $value\n <br>";
  8. }
  9. $headers ='From: '.$_POST["Contact_Email"]."\n";
  10. $headers .='Reply-To: '.$_POST["Contact_Email"]."\n";
  11. $headers .='Content-Type: text/plain; charset="iso-8859-1"'."\n";
  12. $headers .='Content-Transfer-Encoding: 8bit';
  13. $message ="\n".'<html>'."\n".'<head>'."\n".'<title>'."\n".$sujet."\n".'</title>'
  14. ."\n".'</head>'."\n".'<body bgcolor="blue">'."\n".'<font color="yellow" face="Comic Sans Ms">'."\n".'<H1>'."\n".'<br>'.$corps."\n".'</H1>'."\n".'</font>'."\n".'</body>'."\n".'</html>';
  15. if(mail("toto@to.tom", $sujet, $message, $headers))
  16. {
  17. header("Location : index.html" );
  18. }
  19. else
  20. {
  21. echo 'Le message n\'a pu être envoyé, désolé !!!';
  22. }
  23. ?>

Voici ce que me renvoi le serveur mail censé recevoir mon mail !

  1. This is the mail system at host perso1.free.fr.
  2.  
  3. I'm sorry to have to inform you that your message could not
  4. be delivered to one or more recipients. It's attached below.
  5.  
  6. For further assistance, please send mail to <postmaster>
  7.  
  8. If you do so, please include this problem report. You can
  9. delete your own text from the attached returned message.
  10.  
  11. The mail system
  12.  
  13. <to@toto.tom>: host mx1.hotmail.com[IP] said: 550 Your
  14. e-mail was rejected for policy reasons on this gateway. Reasons for
  15. rejection may be related to content such as obscene language, graphics, or
  16. spam-like characteristics (or) other reputation problems. For sender
  17. troubleshooting information, please go to <a href="http://postmaster.msn.com" target="_blank">http://postmaster.msn.com</a>.
  18. Please note: if you are an end-user please contact your E-mail/Internet
  19. Service Provider for assistance. (in reply to MAIL FROM command)

Shino-Genin a dit :
Spammer par quoi ? Le serveur de Free ?

Tu peux mettre ta propre adresse, ou une adresse créé sur un webmail pour l'occasion...


Je ne laiss pas mon adresse sur ce forum, C'EST POUR CA que je ne mets pas mon adresse ou celle à atteindre par le formulaire.
C'est aussi simple que ça !!!!!!!!!
Expert Programmation

Te fout pas de nous : le message d'erreur de Free est clair

Citation :
to@toto.tom>: host mx1.hotmail.com[IP]...


Tu testes avec cet email pourri, c'est juste pour ça que ça marche pas... Essaie avec un vrai mail, tu verras que ce sera bien mieux !!!!!!!

Et ça n'a rien à voir avec l'email que tu laisses ici :o 

J'ai trouvé plus buté que moi ma parole :pt1cable: 

Citation :

marsien a écrit :

Eh ben, c'est pourtant comme ça que ça marche. Donc à refaire et mets l'erreur ici si elle revient :) 

smoon a écrit :

Ceci est le mail que je reçois lorsque je soumets mon formulaire :
(Les adresses mails ont été modifiées, ne pas dire que ça ne peut marcher avec des adresses mail pareil !!!)




LE MOSSIEUUUUUUUUUUUUUU TEEEEE DIIIIIIIIIIIII

Je MOIDIFIE l'adresse mail sur mes post ICI, mais SINON j'ai UNE ADRESSE VALIIIIIIIDE pour mes TEST en REEL :lol: 


PEUT ON PASSER au vrai probleme maintenant SVP :p 

Il ne s'agit pas d'un problème de programmation, ni d'un problème sur les serveurs de FREE.
L'adresse email utilisée pour les tests est chez HOTMAIL.

host mx1.hotmail.com[IP] said: 550 Your
e-mail was rejected for policy reasons on this gateway. Reasons for
rejection may be related to content such as obscene language, graphics, or
spam-like characteristics (or) other reputation problems. For sender
troubleshooting information, please go to http://postmaster.msn.com.
Please note: if you are an end-user please contact your E-mail/Internet
Service Provider for assistance. (in reply to MAIL FROM command)

Or, depuis une quinzaine de jours les serveurs de messagerie Hotmail considèrent les mails de la plupart des serveurs SMTP de la planète comme étant du spam. Il faut tout simplement utiliser une autre adresse email pour faire les tests.
Pour en savoir plus, voir le lien : http://www.freshmango.com/articles/display/?articleID=2...
Lassé par la pub ? Créez un compte