m4nu Posted June 6, 2007 Share Posted June 6, 2007 Hi all. I am having a little problem with a php email form. I have been using it for year. But recently i changed server and it s not working anymore. Here is a link to the webpage http://www.dis-changchun.com/contact_parents_asso.htm. Basicly all the fields validate correclty (Thanks naugboy) but i don t receive any email. I don t know much about php and i have no idea on how to fix this even though i am sure it s very basic. I ll appreciate a lot if you guys could show me the way. And here is the xhtml: <form action="SendForm.php" method="post"/> <ul class ="form"> <li class="gris"><span>Vorname:</span> <input size="35" type="text" name="firstname"/></li> <li ><span>Nachname:</span> <input size="35" type="text" name="lastname"/></li> <li class="gris"><span>E-mail Adresse:</span> <input type="text" size="35" name="email" /></li> <li ><span>Land:</span> <input size="35" type="text" name="country"/></li> <li class="gris"><span>Nachricht:</span> <textarea rows="3" name="message"></textarea></li> <li ><input type="submit" value="senden" /> </li> </ul></form> And here SendForm.php <?php //adresse à laquelle sera envoyé le contenu du formulaire e_tch@hotmail.com $MailTo = "0000@hotmail.fr"; $MailHeader = "From: SchoolWebSite"; //adresse email qui va figurer dans le champ "expéditeur" /* Les routines suivantes permettent à chacune des variables de prendre la valeur des champs du formulaire et de les stocker ensuite dans la variable globale MailBody qui constituera le corps du message */ $Envoi = 1; //initialisation de la variable envoi à 1 if ($_POST['firstname'] == ''){ //nom du champ1 echo("<font face=verdana size=2>You haven't filed your \"Name\".</font><br>"); //message qui s'affiche si le visiteur n'a pas rempli ce champ $Envoi = 0; //si le champ1 n'a pas été rempli, la variable envoi prend la valeur de 0 } else { $MailBody = "Name : $firstname\n"; //si le champ1 contient de l'information, elle est stockée dans la variable MailBody } //// if ($_POST['lastname'] == ''){ echo("<font face=verdana size=2>You haven't filed your \"lastname\".</font><br>"); $Envoi = 0; } else { $MailBody .= "Lastname : $lastname\n"; } //// if ($_POST['email'] == ''){ echo("<font face=verdana size=2>You haven't filed your \"Email\"</font><br>"); $Envoi = 0; } else { $MailBody .= "Email : $email\n"; } //// if ($_POST['country'] == ''){ echo("<font face=verdana size=2> You haven't filed your \"Country\".</font><br>"); $Envoi = 0; } else { $MailBody .= "Country : $country\n"; } //////// if ($_POST['message'] == ''){ echo("<font face=verdana size=2>You haven't filed your \"Message\".</font><br>"); $Envoi = 0; } else { $MailBody .= "Contenu du message: $message\n"; }//// if ($Envoi == 0) echo("Connection lost while sending the form. Retry later or send us directly a mail to this adresse e_tch@hotmail.com<p> </p>"); //Envoi du message if ($Envoi == '1') { //vérification que la variable envoi est bien à 1 $MailSubject = "From the website"; //texte qui va figurer dans le champ "sujet" du email mail($MailTo, $MailSubject, $MailBody, $MailHeader); //envoi du message echo("<p><font face=verdana size=2>Your message has been sended.<br> We ll reply as soon as possible</font>"); echo("<p> </p><p> </p><p align=\"center\"><a href=\"http://www.disc.com\"><strong>Retour</strong></a></p>"); //affichage d'un message de confirmation. } ?> Thx all for your help Quote Link to comment https://forums.phpfreaks.com/topic/54388-form-submition-problem/ Share on other sites More sharing options...
mmarif4u Posted June 6, 2007 Share Posted June 6, 2007 R u sure that ur host provide a mail facility. If yes than u have to change some things in ur php.ini file. If No than u have to ask ur host for further information. Quote Link to comment https://forums.phpfreaks.com/topic/54388-form-submition-problem/#findComment-268948 Share on other sites More sharing options...
m4nu Posted June 6, 2007 Author Share Posted June 6, 2007 Thanks for your answer mmarifau, So there is nothing wrong with the code ? Could you tell me where can i find this php.ini file? Quote Link to comment https://forums.phpfreaks.com/topic/54388-form-submition-problem/#findComment-268951 Share on other sites More sharing options...
MemphiS Posted June 6, 2007 Share Posted June 6, 2007 Ive read over your code briefly i couldnt see any time where you set $Envoi to 1 which would send the mail Solution: <?php //Envoi du message $Envoi =1; // All data has been verified set $Envoi to 1 to mail user if ($Envoi == '1') { //vérification que la variable envoi est bien à 1 $MailSubject = "From the website"; //texte qui va figurer dans le champ "sujet" du email mail($MailTo, $MailSubject, $MailBody, $MailHeader); //envoi du message echo("<p><font face=verdana size=2>Your message has been sended.<br> We ll reply as soon as possible</font>"); echo("<p> </p><p> </p><p align=\"center\"><a href=\"http://www.disc.com\"><strong>Retour</strong></a></p>"); //affichage d'un message de confirmation. } ?> Quote Link to comment https://forums.phpfreaks.com/topic/54388-form-submition-problem/#findComment-268952 Share on other sites More sharing options...
m4nu Posted June 6, 2007 Author Share Posted June 6, 2007 I set the variable Envoi to 1 for default value at the begining of the code. <?php //adresse à laquelle sera envoyé le contenu du formulaire e_tch@hotmail.com $MailTo = "0000@hotmail.fr"; $MailHeader = "From: SchoolWebSite"; //adresse email qui va figurer dans le champ "expéditeur" /* Les routines suivantes permettent à chacune des variables de prendre la valeur des champs du formulaire et de les stocker ensuite dans la variable globale MailBody qui constituera le corps du message */ [b]$Envoi = 1;[/b] //initialisation de la variable envoi à 1 Is this syntax correct? Quote Link to comment https://forums.phpfreaks.com/topic/54388-form-submition-problem/#findComment-268954 Share on other sites More sharing options...
m4nu Posted June 7, 2007 Author Share Posted June 7, 2007 Can someone help me out please , i am really stuck here, and i have to deliver this website very soon. Quote Link to comment https://forums.phpfreaks.com/topic/54388-form-submition-problem/#findComment-269967 Share on other sites More sharing options...
per1os Posted June 7, 2007 Share Posted June 7, 2007 Your mail header is invalid: $MailHeader = "From: shool@schoolweb.com\r\n"; //adresse email qui va figurer dans le champ "expéditeur" Note the actual Email address, the full email address is required. Also note the \r\n at the end. I would suggest reading through www.php.net/mail the mail function and formatting it properly. Quote Link to comment https://forums.phpfreaks.com/topic/54388-form-submition-problem/#findComment-269971 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.