Jump to content

Recommended Posts

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 by gwolff2005

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 by mrMarcus

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.

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 by mrMarcus

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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.