gwolff2005 Posted November 22, 2012 Share Posted November 22, 2012 (edited) Hi guys. I need your help. I have a contact form, on which the ip address is shown, but it does not get send with the form, for whatever reason... What am I doing wrong?? Thanks for your help!!! <?php // wenn das Formular übermittelt wurde if(isset($_POST['abschicken'])){ while(list($feld,$wert)=each($_POST)){ // übermittelte Inhalte "entschärfen" $wert=preg_replace("/(content-type:|bcc:|cc:|to:|from:)/im", "",$wert); $feld=$wert; // die übermittelten Variablen werden zum "Text der Email" zusammengefasst if($feld!="abschicken") $mailnachricht.=ucfirst($feld).": $wert\n"; } $mailnachricht.="\nDatum/Zeit: ". date("d.m.Y H:i:s"); $ip=@$REMOTE_ADDR; echo "<input type='hidden' value='$ip' />"; // Ãœberprüfen ob alle Pflichtfelder gefüllt sind empty($vorname) ? $err[] = "<p>- Bitte den Vornamen angeben.</p>" : false; empty($email) ? $err[] = "<p>- Bitte die Email-Adresse angeben.</p>" : false; empty($text) ? $err[] = "<p>- Welchen Wunsch haben Sie? Bitte den Text eingeben.</p>" : false; // wenn nicht, werden die Fehlermeldungen ausgegeben und das "halbgefüllte" Formular angezeigt if(!empty($err)) { echo "<p>Bitte korrigieren Sie folgende Fehler:</p>"; foreach($err as $fehler){ echo $fehler; } ?> <form action="<?php echo $_SERVER['kontakt/PHP_SELF']; ?>" method="post"> <table width="100%" border="0" cellpadding="3" cellspacing="1"> <tr> <td width="140" align="right" class="style18"><div align="left" class="style22">Nachname:</div></td> <td align="left"><input type="text" name="nachname" value="<?php echo $nachname; ?>" style="width:100%;" /></td> </tr> <tr> <td align="right" class="style18"><div align="left" class="style22">Vorname:</div></td> <td align="left"><input type="text" name="vorname" value="<?php echo $vorname; ?>" style="width:100%" /></td> </tr> <tr> <td align="right" class="style18"><div align="left">Firma:</div></td> <td align="left"><input type="text" name="firma" value="<?php echo $firma; ?>" style="width:100%" /></td> </tr> <tr> <td align="right" class="style18"><div align="left">Postanschrift:</div></td> <td align="left"><input type="text" name="strasse" value="<?php echo $strasse; ?>" style="width:100%" /></td> </tr> <tr> <td align="right" class="style18"><div align="left">Telefon:</div></td> <td align="left"><input type="text" name="telefon" value="<?php echo $telefon; ?>" style="width:100%" /></td> </tr> <tr> <td align="right" class="style18"><div align="left" class="style22">E-Mail:</div></td> <td align="left"><input type="text" name="email" value="<?php echo $email; ?>" style="width:100%" /></td> </tr> <tr> <td align="right" class="style18"><div align="left">Ihre IP Adresse</div></td> <td align="left"><input type="hidden" name="ip" value="<?php echo $_SERVER['REMOTE_ADDR']; ?>" style="width:100%" /></td> </tr> <tr> <td colspan="2"><textarea rows="12" style="width:100%" name="text"><?php echo $text; ?></textarea></td> <td></td> </tr> <tr> <td colspan="2" align="left" nowrap><input name="reset" type="reset" style="width:49%" value="Formular löschen" /> <input type="submit" name="abschicken" class="button" value="Formular absenden" style="width:49%" /></td> </tr> </table> <?php // sind keine Fehler vorhanden, wird die Email versendet } else { $mailbetreff="Kontaktformular ".$_SERVER['HTTP_HOST']; // HIER DIE EMPFÄNGER EMAIL-ADRESSE ANPASSEN!!! echo (mail("guntmar@guntmarwolff.com", $mailbetreff, $mailnachricht, "From: $email")) ? "<p>Vielen Dank für Ihre Email.</p>": "<p>Ein Fehler ist aufgetreten!</p>"; ; } // das Formular welches als erstes dem Besucher angezeigt wird } else { ?> </form> <form action="<?php echo $_SERVER['kontakt/PHP_SELF']; ?>" method="post"> <table width="100%" border="0" cellpadding="3" cellspacing="1"> <tr> <td width="140" align="right" class="style18"><div align="left" class="style22">Nachname:</div></td> <td align="left"><input type="text" name="nachname2" value="" style="width:100%;" /></td> </tr> <tr> <td align="right" class="style18"><div align="left" class="style22">Vorname:</div></td> <td align="left"><input type="text" name="vorname" value="" style="width:100%" /></td> </tr> <tr> <td align="right" class="style18"><div align="left">Firma:</div></td> <td align="left"><input type="text" name="firma" value="" style="width:100%" /></td> </tr> <tr> <td align="right" class="style18"><div align="left">Postanschrift:</div></td> <td align="left"><input type="text" name="strasse" value="" style="width:100%" /></td> </tr> <tr> <td align="right" class="style18"><div align="left">Telefon:</div></td> <td align="left"><input type="text" name="telefon" value="" style="width:100%" /></td> </tr> <tr> <td align="right" class="style18"><div align="left" class="style22">E-Mail:</div></td> <td align="left"><input type="text" name="email" value="" style="width:100%" /></td> </tr> <tr> <td align="right" class="style18"><div align="left">Ihre Ip Adresse:</div></td> <td align="left"><input type="hidden" name="ip" value="" class="style18"> <span class="style18"><?php echo $_SERVER['REMOTE_ADDR']; ?></span></td> </tr> <tr> <td colspan="2"><textarea rows="12" style="width:100%" name="text"></textarea></td> <td></td> </tr> <tr> <td colspan="2" align="left" nowrap><input name="reset" type="reset" style="width:49%" value="Formular löschen" /> <input type="submit" name="abschicken" value="Formular absenden" style="width:49%" /></td> </tr> </table> <!-- bitte lassen Sie diesen Link sichtbar auf Ihrer Seite. Danke! --> <?php } ?> </form> </div> Edited November 22, 2012 by gwolff2005 Quote Link to comment https://forums.phpfreaks.com/topic/271038-ip-address-does-not-get-sent-please-help/ Share on other sites More sharing options...
mrMarcus Posted November 22, 2012 Share Posted November 22, 2012 Can't read your code. Please edit/repost. Quote Link to comment https://forums.phpfreaks.com/topic/271038-ip-address-does-not-get-sent-please-help/#findComment-1394429 Share on other sites More sharing options...
gwolff2005 Posted November 22, 2012 Author Share Posted November 22, 2012 (edited) I edited again Edited November 22, 2012 by gwolff2005 Quote Link to comment https://forums.phpfreaks.com/topic/271038-ip-address-does-not-get-sent-please-help/#findComment-1394431 Share on other sites More sharing options...
mrMarcus Posted November 22, 2012 Share Posted November 22, 2012 (edited) Not sure if this is just a typo: <form action="<?php echo $_SERVER['kontakt/PHP_SELF']; ?>" method="post"> Thinking you meant to do?: <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> And I'm assuming you're referring to this line: <td align="left"><input type="hidden" name="ip" value="" class="style18"><span class="style18"><?php echo $_SERVER['REMOTE_ADDR']; ?></span></td> You're clearly not sending the IP address within the form as you have not added it to the input value. Edited November 22, 2012 by mrMarcus Quote Link to comment https://forums.phpfreaks.com/topic/271038-ip-address-does-not-get-sent-please-help/#findComment-1394436 Share on other sites More sharing options...
kicken Posted November 22, 2012 Share Posted November 22, 2012 What am I doing wrong?? You're using the wrong variable name. You're using $REMOTE_ADDR, but should be using $_SERVER['REMOTE_ADDR']: $mailnachricht.="\nDatum/Zeit: ". date("d.m.Y H:i:s"); $ip=@$REMOTE_ADDR; echo "<input type='hidden' value='$ip' />"; If you would have not used the error-suppression operator, you would have gotten a big fat E_NOTICE error telling you that. Quote Link to comment https://forums.phpfreaks.com/topic/271038-ip-address-does-not-get-sent-please-help/#findComment-1394437 Share on other sites More sharing options...
gwolff2005 Posted November 22, 2012 Author Share Posted November 22, 2012 mrMarcus, kicken, thanks for your help. It is still not sending me the IP In the enmail I get it just says Ip and then blank... while on the internet it shows the ip address. Quote Link to comment https://forums.phpfreaks.com/topic/271038-ip-address-does-not-get-sent-please-help/#findComment-1394490 Share on other sites More sharing options...
mrMarcus Posted November 22, 2012 Share Posted November 22, 2012 (edited) Are you passing the IP through the form like I suggested? It's a hidden form field; without a value to it, you will not receive the IP address. Aside from that, it's not necessary to add it to the form in the first place since it's hidden. Just add it directly to your mail function. Edited November 22, 2012 by mrMarcus Quote Link to comment https://forums.phpfreaks.com/topic/271038-ip-address-does-not-get-sent-please-help/#findComment-1394491 Share on other sites More sharing options...
gwolff2005 Posted November 22, 2012 Author Share Posted November 22, 2012 mrMarcus, I am quite a php beginner, so the only thing I can say: that putting all bits and pieces together it does not show the iP. What do I need to add/change in order for it to works. I really appreciate your help. Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/271038-ip-address-does-not-get-sent-please-help/#findComment-1394492 Share on other sites More sharing options...
gwolff2005 Posted November 22, 2012 Author Share Posted November 22, 2012 (edited) Hi Mr. Marcus, What do I need to write in order to add it to the mail function. I am on this the whole day already and cannot get it sorted. Thank you so much!! Edited November 22, 2012 by gwolff2005 Quote Link to comment https://forums.phpfreaks.com/topic/271038-ip-address-does-not-get-sent-please-help/#findComment-1394495 Share on other sites More sharing options...
mrMarcus Posted November 22, 2012 Share Posted November 22, 2012 mrMarcus, I am quite a php beginner, so the only thing I can say: that putting all bits and pieces together it does not show the iP. What do I need to add/change in order for it to works. I really appreciate your help. Thank you. I showed you already. You're not passing the IP address through the form. <td align="left"><input type="hidden" name="ip" value="" class="style18"><span class="style18"><?php echo $_SERVER['REMOTE_ADDR']; ?></span></td> You're clearly not sending the IP address within the form as you have not added it to the input value. See how value="" is empty? You need to add $_SERVER['REMOTE_ADDR'] to the value attribute within the IP input, like so: <td align="left"><input type="hidden" name="ip" value="<?php echo $_SERVER['REMOTE_ADDR']; ?>" class="style18"><span class="style18"><?php echo $_SERVER['REMOTE_ADDR']; ?></span></td> Not when you collect your $_POST'ed values from the form (using while(list($feld,$wert)=each($_POST))), IP will have a value. HOWEVER, since IP is a hidden input to begin with, and the user is not able to change the value, there really is no logical reason (as per your usage) to have it in the form. You could just append it to the $mailnachricht variable. But do what I suggested above first, and that will get things working. Quote Link to comment https://forums.phpfreaks.com/topic/271038-ip-address-does-not-get-sent-please-help/#findComment-1394496 Share on other sites More sharing options...
gwolff2005 Posted November 22, 2012 Author Share Posted November 22, 2012 Hi mr Marcus, I did that, godaddy seems to have a mailqueue again, so I cannot see teh results right now. I will let you know as soon as I get the mail. Hopefully it works. Thank you so much. Quote Link to comment https://forums.phpfreaks.com/topic/271038-ip-address-does-not-get-sent-please-help/#findComment-1394498 Share on other sites More sharing options...
gwolff2005 Posted November 22, 2012 Author Share Posted November 22, 2012 Hey it works!!!!! Thank you very much!!!!!!! I really appreciate your help. Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/271038-ip-address-does-not-get-sent-please-help/#findComment-1394500 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.