Hexagon Posted December 8, 2009 Share Posted December 8, 2009 Hello i need some help with a php script that sends email and then it reloades and includes the same site the email form is on. Now i can only display the echo message "email successfully sent" on the bottom or the right of the page after it reloades, but id like it to be displayed under submit button. Any ideas? thanks in advance! Here the send.php: <? include 'kontakt.html'; ?> <div id="form1" ><? $header = 'MIME-Version: 1.0' . "\r\n"; $header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $header .= 'From: '.$_POST['firstname'].' '.$_POST['lastname'].' <'.$_POST['email'].'>' . "\r\n"; $html = '<html><body'; echo 'Message successfully sent.'; $html .= 'Name: '.$_POST['firstname'].' '.$_POST['lastname'].'<br>'; $html .= 'Email: '.$_POST['email'].'<br>'; $html .= 'Phone: '.$_POST['phone'].'<br><br>'; $html .= 'Message:'.$_POST['message']; $html .= '</body></html>'; $studio = $_POST['studio']; if ($studio == 1) $adress = 'bloodmonic@gmail.com'; if ($studio == 2) $adress = 'bloodmonic@gmail.com'; if ($studio == 3) $adress = 'bloodmonic@gmail.com'; if ($studio == 4) $adress = 'bloodmonic@gmail.com'; if ($studio == 5) $adress = 'bloodmonic@gmail.com'; mail($adress,'Message from styluxhair.de',$html,$header); ?></div> Here the html file: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta name="description" content="Stylux ist Spezialist für die kosmetische Behandlung von Haarausfall und hat seit 2005 tausende Menschen erfolgreich behandelt."> <meta name="keywords" content="haarausfall, haare, haarausfall stoppen, Alopezie, alopecia, areata, haarverlust, Haarbehandlungen, Behandlung, glatze, kopfhaut,Kahlköpfigkeit, Geheimratsecken, Schuppen, gegen haarausfall, Haarausfall Frauen Männer, Haarwuchsmittel, Haarwuchs, Ursachen Haarausfall, Stress, hormoneller Haarausfall, erblicher Haarausfall, kreisrunder Haarausfall, diffuser Haarausfall, altersbedingter Haarausfall, Haartransplantation, Transplantation, Propecia, Proscar, Finasterid, Minoxidil, Regaine, anlagebedingt, Hormone, shampoo, Perücke, Zweithaar, Laser"> <title>Stylux | HAIR AND LASER TREATMENT</title> <meta name="robots" content="index,follow" > <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" > <link rel="stylesheet" type="text/css" href="files/style.css"> <link rel="shortcut icon" href="files/images/favicon.ico"> <script language="javascript"> AC_FL_RunContent = 0; </script> <script type="text/javascript" src="referenzen.php-Dateien/jquery-1.js"></script> <script type="text/javascript" src="referenzen.php-Dateien/slimbox2.js"></script> <script language="javascript"> DetectFlashVer = 0; </script> <script src="referenzen.php-Dateien/AC_RunActiveContent.js" language="javascript"></script> <script language="JavaScript" type="text/javascript"> <!-- var requiredMajorVersion = 8; var requiredMinorVersion = 0; var requiredRevision = 24; // --> </script> </head> <body> <div id="center"><div id="wrapper"> <div id="logo"><a href="index.html"><img src="files/images/logo.png" style="border-style: none"></a></div> <div class="menu"> <table align="right" border="0" cellpadding="0" cellspacing="0" height="29"> <tbody><tr> <td class="menuitem"><a href="index.html" class="menuitem">Über Stylux</a></td> <td><img src="files/images/menudivider.png"></td> <td class="menuitem"><a href="haarausfall.html" class="menuitem">Haarausfall</a></td> <td><img src="files/images/menudivider.png"></td> <td class="menuitem"><a href="behandlungsmethoden.html" class="menuitem">Behandlungsmethoden</a></td> <td><img src="files/images/menudivider.png"></td> <td class="menuitem"><a href="fragenundantworten.html" class="menuitem">Fragen und antworten</a></td> <td><img src="files/images/menudivider.png"></td> <td class="menuitem"><a href="referenzen.html" class="menuitem">Referenzen</a></td> <td><img src="files/images/menudivider.png"></td> <td class="menuitem"><a href="links.html" class="menuitem">Links</a></td> <td><img src="files/images/menudivider.png"></td> <td class="menuitem"><a href="kontakt.html" class="menuitemsel">Kontakt</a></td> <td> </td> </tr> </tbody></table> </div> <div id=Header> </script><embed src="files/topflash.swf" quality="best" pluginspage="http://www.macromedia.com/go/getflashplayer" play="true" loop="true" scale="noscale" wmode="window" devicefont="false" bgcolor="#ffffff" name="topflash" menu="true" allowscriptaccess="sameDomain" allowfullscreen="false" salign="lt" type="application/x-shockwave-flash" align="left" height="320" width="982"> <noscript> <a href="http://www.macromedia.com/go/getflash/">Get Flash</a> </noscript> </div> <div id="main"> <div id="links"> <div id="form1"> <div style="float: left; width: 680px;"> <h1>Kontaktieren Sie uns</h1> <div id=text style="margin-left:15px; margin-right:15px; margin-bottom:15px;"> Um uns eine Email zu schreiben, nutzen Sie bitte dieses Kontaktformular.<br> Gerne werden wir Ihre Fragen umgehend beantworten. <br> <br> (*) Die mit einem Stern gekennzeichneten Felder sind Pflichtfelder. </div> <form name="mailform" method="post" action="send.php" style="margin:15px;"> <table border="0" cellpadding="2" cellspacing="2"> <tbody><tr> <td align="right">Vorname* </td> <td><input name="firstname" style="width: 150px;" type="text"> </td> <td align="right">Nachname* </td> <td><input name="lastname" style="width: 150px;" type="text"></td> </tr> <tr> <td align="right">Telefon* </td> <td><input name="phone" style="width: 150px;" type="text"></td> <td align="right">Email* </td> <td><input name="email" style="width: 150px;" type="text"> </td> </tr> <tr> <td align="right">Stylux Harstuudio <br>in Ihrer Nähe* </td> <td><select name="studio" style="width: 150px;"> <option selected="selected" value="1">Hamburg</option> <option value="2">Stockholm</option> <option value="3">Göteborg</option> <option value="4">Borås</option> <option value="5">Oslo</option> </select></td> </tr> <tr> <td colspan="4"><br>Ihre Nachricht*<br><textarea name="message" style="width: 100%; height: 150px;"></textarea></td> </tr> </tbody></table> <input value="Senden" type="submit"></form> </div> </div> <div id="form2" style="align:left;"> <div id="hhlux"><img src="files/images/hhlux.png" style="float:right; margin:15px;"></div> <div id=text style="margin-left:15px; margin-right:15px; margin-bottom:40px; padding-top:35px;"> <h1>Stylux Hamburg</h1> Neuer Wall 36 <br> 20354 Hamburg <br> Tel: +49 (0)40 / 38 64 99 90 <br> Email: <a class="blue" href="mailto:hamburg@styluxhair.de">hamburg@styluxhair.de</a> </div> </div> <div id="form2" style="align:left;""> <div id="hhlux"><img src="files/images/stylux.png" style="float:right; margin:15px;"></div> <div id=text style="margin-left:15px; margin-right:15px; margin-bottom:40px; padding-top:35px;"> <h1>Stylux Oslo</h1> Gabelsgt.19 <br> 0272 Oslo <br> Tel: +47 22 / 44 55 94 <br> Email: <a class="blue" href="mailto:oslo@stylux.no">oslo@stylux.no</a> </div> </div> <div id="form2" style="align:left;""> <div id="hhlux"><img src="files/images/stylux.png" style="float:right; margin:15px;"></div> <div id=text style="margin-left:15px; margin-right:15px; margin-bottom:25px; padding-top:35px;"> <h1>Stylux Stockholm</h1> Strindbergsgatan 52 <br> 115 31 Stockholm <br> +46 (0)8 / 41 05 15 00 <br> T-Karlaplan, uppgång: Valhallavägen, Tessinparken <br> Email: <a class="blue" href="mailto:stockholm@stylux.se">stockholm@stylux.se</a> </div> </div> <div id="form2" style="align:left;""> <div id="hhlux"><img src="files/images/stylux.png" style="float:right; margin:15px;"></div> <div id=text style="margin-left:15px; margin-right:15px; margin-bottom:40px; padding-top:35px;"> <h1>Stylux Göteborg</h1> Vasagatan 21 <br> 411 24 Göteborg <br> Tel: +46 (0)31 / 711 19 04 <br> Email: <a class="blue" href="mailto:goteborg@stylux.se">goteborg@stylux.se</a> </div> </div> <div id="form2" style="align:left;""> <div id="hhlux"><img src="files/images/stylux.png" style="float:right; margin:15px;"></div> <div id=text style="margin-left:15px; margin-right:15px; margin-bottom:15px; padding-top:35px;"> <h1>Stylux Borås</h1> Västerlånggatan 30-32 <br> 503 30 Borås <br> Tel: +46 (0)33 / 430 60 60 <br> Email: <a class="blue" href="mailto:boras@stylux.se">boras@stylux.se</a> </div> </div> </div> <div id="rechts"> <div class="sidebar2"><h1 style="text-align: center;">Kostenlose Beratung</h1> <p>Nehmen Sie mit uns Kontakt auf, um einen Termin für eine kostenlose Haaruntersuchung und ein Beratungsgespräch zu vereinbaren.</p> <p>Rufen Sie uns direkt an oder vereinbaren Sie einen Termin online über unser <b><a href="kontakt.html">Kontaktformular.</a></b></p> <h1 style="text-align: center;">+49 (0)40 / 38 64 99 90</h1> <center><form name="mailform" method="post" action="send.php"> <br> <br> <center><div id="bartxt" style="color: #515356;"><h4>Vorname</h4</div><input name="firstname" style="width: 150px; clear:right; float:right;" type="text"> <br> <br> <center><div id="bartxt" style="color: #515356;"><h4>Nachname</h4</div><input name="lastname" style="width: 150px; clear:right; float:right;" type="text"> <br> <br> <center><div id="bartxt" style="color: #515356;"><h4>Telefon</h4</div><input name="phone" style="width: 150px; clear:right; float:right;" type="text"> <br> <br> <center><div id="bartxt" style="color: #515356;"><h4>Email</h4</div><input name="email" style="width: 150px; clear:right; float:right;" type="text"> <br> <p><h4>Wo haben Sie uns gefunden?</h4></p> <br> <br> <td><select name="studio" style="width: 150px; float:right;"> <option selected="selected" value="1">Google</option> <option value="2">U- und S-Bahn</option> <option value="3">Tageszeitung</option> <option value="4">Wochenblatt</option> <option value="5">Magazin</option> <option value="6">Sonstiges</option> </select></td> <br> <br> <input value="Senden" type="submit" style="float:right;"> <br> <br> </div> <br> <div class="sidebar2"><h1 style="text-align: center;">Öffnungszeiten</h1> <p style="text-align: center;">Montag bis Freitag: 10:00 bis 20:00 Uhr</p> </div> <br> <div class="sidebar2"><h1 style="text-align: center;">Finanzierung</h1> <p style="text-align: center;"><img src="files/images/medipaylogo.gif"></p> <p>Durch unseren Partner medipay bieten wir Ihnen eine flexible Lösung für <b><a href="finanzierungsmoglichkeiten.html">Finanzierungsmöglichkeiten</a></b>.</p> </div><br> </div> </div> <div id=footer><div style="float:left;">copyright stylux 2009 contact <a href="mailto:info@styluxhair.de">info@styluxhair.de</a></div><div style="float: right; padding-right: 19px;"><a href="impressum.html">Impressum</a></div></div> </div> </div></div> <script type="text/javascript"> var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); </script> <script type="text/javascript"> try { var pageTracker = _gat._getTracker("UA-6191579-2"); pageTracker._trackPageview(); } catch(err) {}</script> </body> </html> Quote Link to comment Share on other sites More sharing options...
raytri Posted December 8, 2009 Share Posted December 8, 2009 Since it doesn't look like you're actually checking whether the message was successfully sent or not, you could make it work like this: 1. Add a hidden "redirect" field to your form that redirects to the same page the form is on, but passes a variable indicating the message has been sent. <input type="hidden" name="redirect" value="http://your.host/to/file.html?sent=sent"> 2. Add a $_GET statement at the top of the page to receive the SENT variable: $sent=$_GET['sent']; 3. Add on IF statement to the bottom of the form, underneath the submit button, that displays if $sent is present: if (isset($sent)) {echo "<p>Message sent.</p>";} Quote Link to comment Share on other sites More sharing options...
Hexagon Posted December 8, 2009 Author Share Posted December 8, 2009 Thx for your reply i have now added what you told me to the kontakt.html but it still doesnt show the sent message. instead it lets my page look a bit displaced maybe i should add that the kontakt.html holds the form and sends the data to the send.php to be sent via mail which works great then the send.php includes kontakt.html into itself. so should i add anything to the .php dile instead of the html document? Quote Link to comment Share on other sites More sharing options...
raytri Posted December 8, 2009 Share Posted December 8, 2009 Remove the kontact.html include from the send.php file. The code I gave you tells the browser to do two things: 1. Send the form data to "send.php" for processing; 2. Instead of displaying "send.php", display the page listed in the "redirect" input field. With send.php including kontact.html, the browser is trying to display the page twice. Also, make sure the "redirect" URL is an absolute link (with the full "http://"). Quote Link to comment Share on other sites More sharing options...
raytri Posted December 8, 2009 Share Posted December 8, 2009 The other problem might be that your form page must have the .php extension. So it should be "kontact.php" instead of "kontact.html". Also, make sure your $_GET statement and IF statement are wrapped in <?php ?> tags. You can also remove the "Message sent" echo from send.php. It's not harming anything by being there, but it will never be seen by anyone. If it still doesn't work, please post the relevant code from kontact.php Quote Link to comment Share on other sites More sharing options...
Hexagon Posted December 8, 2009 Author Share Posted December 8, 2009 ok thank you im trying it right now ill let you know in a bit if it works Quote Link to comment Share on other sites More sharing options...
Hexagon Posted December 8, 2009 Author Share Posted December 8, 2009 ok i tried it now, i renamed the kontakt.html to kontakt.php then in the head i added <?PHP $sent=$_GET['sent']; ?> at the bottom of the head. <head> <meta name="description" content="Stylux ist Spezialist für die kosmetische Behandlung von Haarausfall und hat seit 2005 tausende Menschen erfolgreich behandelt."> <meta name="keywords" content="haarausfall, haare, haarausfall stoppen, Alopezie, alopecia, areata, haarverlust, Haarbehandlungen, Behandlung, glatze, kopfhaut,Kahlköpfigkeit, Geheimratsecken, Schuppen, gegen haarausfall, Haarausfall Frauen Männer, Haarwuchsmittel, Haarwuchs, Ursachen Haarausfall, Stress, hormoneller Haarausfall, erblicher Haarausfall, kreisrunder Haarausfall, diffuser Haarausfall, altersbedingter Haarausfall, Haartransplantation, Transplantation, Propecia, Proscar, Finasterid, Minoxidil, Regaine, anlagebedingt, Hormone, shampoo, Perücke, Zweithaar, Laser"> <title>Stylux | HAIR AND LASER TREATMENT</title> <meta name="robots" content="index,follow" > <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" > <link rel="stylesheet" type="text/css" href="files/style.css"> <link rel="shortcut icon" href="files/images/favicon.ico"> <script language="javascript"> AC_FL_RunContent = 0; </script> <script type="text/javascript" src="referenzen.php-Dateien/jquery-1.js"></script> <script type="text/javascript" src="referenzen.php-Dateien/slimbox2.js"></script> <script language="javascript"> DetectFlashVer = 0; </script> <script src="referenzen.php-Dateien/AC_RunActiveContent.js" language="javascript"></script> <script language="JavaScript" type="text/javascript"> <!-- var requiredMajorVersion = 8; var requiredMinorVersion = 0; var requiredRevision = 24; // --> </script> <?PHP $sent=$_GET['sent']; ?> then i put the <input type="hidden" name="redirect" value="http://hexagon.jlkfree.com/kontakt.html?sent=sent"> into the mailform of the kontakt.php like this: <form name="mailform" method="post" action="send.php" style="margin:15px;"> <input type="hidden" name="redirect" value="http://hexagon.jlkfree.com/kontakt.php?sent=sent"> <table border="0" cellpadding="2" cellspacing="2"> <tbody><tr> <td align="right">Vorname* </td> <td><input name="firstname" style="width: 150px;" type="text"> </td> <td align="right">Nachname* </td> <td><input name="lastname" style="width: 150px;" type="text"></td> </tr> <tr> <td align="right">Telefon* </td> <td><input name="phone" style="width: 150px;" type="text"></td> <td align="right">Email* </td> <td><input name="email" style="width: 150px;" type="text"> </td> </tr> <tr> <td align="right">Stylux Harstuudio <br>in Ihrer Nähe* </td> <td><select name="studio" style="width: 150px;"> <option selected="selected" value="1">Hamburg</option> <option value="2">Stockholm</option> <option value="3">Göteborg</option> <option value="4">Borås</option> <option value="5">Oslo</option> </select></td> </tr> <tr> <td colspan="4"><br>Ihre Nachricht*<br><textarea name="message" style="width: 100%; height: 150px;"></textarea></td> </tr> </tbody></table> <input value="Senden" type="submit"></form> And then added the <?PHP if (isset($sent)) {echo "<p>Message sent.</p>";} ?> under the submit button like this: <input value="Senden" type="submit"></form> <?PHP if (isset($sent)) {echo "<p>Message sent.</p>";} ?> but after clicking submit it just takes me to the send.php and stays there, the mail is sent though. Quote Link to comment Share on other sites More sharing options...
Hexagon Posted December 8, 2009 Author Share Posted December 8, 2009 oh and my php file now looks like this: <? $header = 'MIME-Version: 1.0' . "\r\n"; $header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $header .= 'From: '.$_POST['firstname'].' '.$_POST['lastname'].' <'.$_POST['email'].'>' . "\r\n"; $html = '<html><body'; $html .= 'Name: '.$_POST['firstname'].' '.$_POST['lastname'].'<br>'; $html .= 'Email: '.$_POST['email'].'<br>'; $html .= 'Phone: '.$_POST['phone'].'<br><br>'; $html .= 'Message:'.$_POST['message']; $html .= '</body></html>'; $studio = $_POST['studio']; if ($studio == 1) $adress = 'bloodmonic@gmail.com'; if ($studio == 2) $adress = 'bloodmonic@gmail.com'; if ($studio == 3) $adress = 'bloodmonic@gmail.com'; if ($studio == 4) $adress = 'bloodmonic@gmail.com'; if ($studio == 5) $adress = 'bloodmonic@gmail.com'; mail($adress,'Message from styluxhair.de',$html,$header); ?> Quote Link to comment Share on other sites More sharing options...
raytri Posted December 8, 2009 Share Posted December 8, 2009 You've got nearly everything right. But looking at your page source, the value of your redirect field is still using "kontact.html": <input type="hidden" name="redirect" value="http://hexagon.jlkfree.com/kontakt.html?sent=sent"> It should use "kontact.php": <input type="hidden" name="redirect" value="http://hexagon.jlkfree.com/kontakt.php?sent=sent"> Quote Link to comment Share on other sites More sharing options...
Hexagon Posted December 8, 2009 Author Share Posted December 8, 2009 yea i just noticed and changed that but its still not working any ideas? thx for your time btw Quote Link to comment Share on other sites More sharing options...
Hexagon Posted December 8, 2009 Author Share Posted December 8, 2009 dont i have to add something in the php file? because i m stuck on the send.php after clicking submit maybe something like go back to site or something? Quote Link to comment Share on other sites More sharing options...
raytri Posted December 8, 2009 Share Posted December 8, 2009 Now you've got extra quote marks in the redirect URL: <input type="hidden" name="redirect" value="http://hexagon.jlkfree.com/kontakt.php?sent="sent""> Copy this code *exactly* and replace your redirect input with it: <input type="hidden" name="redirect" value="http://hexagon.jlkfree.com/kontakt.php?sent=sent"> You don't have to make any changes to send.php, because with redirect the form data is sent to send.php for processing but the browser is sent to the redirect URL. That's the whole point of redirect. Quote Link to comment Share on other sites More sharing options...
Hexagon Posted December 8, 2009 Author Share Posted December 8, 2009 yea i played around a bit with the quote marks but its not working i dunno i have exactly the code that you posted. i wonder why it sends me to the send.php site all the time. i mean, shouldnt it just send the data to send.php and then let send.php handle the sending without going to send.php? thats what the redirect is for right? Quote Link to comment Share on other sites More sharing options...
raytri Posted December 8, 2009 Share Posted December 8, 2009 It's possible the problem is that the input line has some HTML errors. They shouldn't really affect the function, but.... try this. Replace the redirect line with this: <p><input type="hidden" name="redirect" value="http://hexagon.jlkfree.com/kontakt.php?sent=sent" /></p> Quote Link to comment Share on other sites More sharing options...
Hexagon Posted December 8, 2009 Author Share Posted December 8, 2009 not working either i also tried replacing the post method of the form with get and now it shows the redirect in the url bar but still is stuck on the send.php Quote Link to comment Share on other sites More sharing options...
raytri Posted December 8, 2009 Share Posted December 8, 2009 Hmm. Sorry to say, I'm not sure why that's not working. I'm either missing something, or there are errors in the page elsewhere that are messing this up. Let's try a different route: 1. Delete the "redirect" line. 2. Add the following to the bottom of your send.php file: header ('Location: http://hexagon.jlkfree.com/kontakt.php?sent=sent'); Quote Link to comment Share on other sites More sharing options...
Hexagon Posted December 8, 2009 Author Share Posted December 8, 2009 gives me this error: Warning: Cannot modify header information - headers already sent by (output started at /home/hexagonj/public_html/send.php:2) in /home/hexagonj/public_html/send.php on line 25 i feel like i wanna hang myslef lol Quote Link to comment Share on other sites More sharing options...
raytri Posted December 8, 2009 Share Posted December 8, 2009 Hang in there! Try putting the "header" line at the top of the send.php file. Quote Link to comment Share on other sites More sharing options...
Hexagon Posted December 8, 2009 Author Share Posted December 8, 2009 OMG IT WORKS! Thank you so much man this is awesome! Quote Link to comment 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.