Jump to content

Recommended Posts

I am teaching myself PHP and having trouble with parsing data from a <form>.  I am having my data emailed to me, but the data does not seem to be picking up the user's IP address, the Browser type, the URL that he/she came from, nor the email address they are entering on the form.  Can someone look at the both code files [below] and offer any help?

 

Thank you very much in advance.

 

 

form.php

======

<Form Method="POST" Action="./php/contactform.php">

<?php

$ipi = getenv("REMOTE_ADDR");

$httprefi = getenv("HTTP_REFERER");

$httpagenti = getenv("HTTP_USER_AGENT");

?>

<input type="hidden" name="ip" value="<?php echo $ipi ?>" />

<input type="hidden" name="httpref" value="<?php echo $httprefi ?>" />

<input type="hidden" name="httpagent" value="<?php echo $httpagenti ?>" />

<Center>

<B>Contact Form</b><b r><b r>

<Table>

  <TR>

    <TD align=right>Name</td>

    <TD><input type="text" name="name" size="47"></td>

  </tr>

  <TR>

    <TD align=right>Subject</td>

    <TD><input type="text" name="subject" size="47"></td>

  </tr>

  <TR>

    <TD align=right>Email</td>

    <TD><input type="text" name="Email" size="47"></td>

  </tr>

  <TR>

    <TD align=right>Question<b r>or &nbsp &nbsp &nbsp <b r>Comment</td>

    <TD><textarea name="question-comment" rows="4" cols="36"></textarea></td>

  </tr>

</table>

</center>

<b r><b r>

<Center>

<Input Type="SUBMIT" Value="Submit" Name="SUBMIT">&nbsp &nbsp

<Input Type="RESET" Value="Reset" Name="RESET">

</center>

 

 

 

contactform.php

===========

<?php

 

$ip = $_POST['ip'];

$httpref = $_POST['httpref'];

$httpagent = $_POST['httpagent'];

$name = $_POST['name'];

$email = $_POST['email'];

$comment = $_POST['question-comment'];

$subject = $_POST['subject'];

 

if (eregi('http:', $comment)) {

die ("Do NOT try that! ! ");

}

 

//  if(empty($name) || empty($comment)) {

//  echo "<h2>Use Back - fill in all fields</h2>\n";

//  die ("Use back! ! ");

//  }

 

$todayis = date("I, F j, Y, G:i a");

$subject = $subject;

$comment = stripcslashes($comment);

$message = " $todayis [EST] \n

Attention: $subject \n

Message: $comment \n

From: $name ($email)\n

EMail: $email \n

Additional Info : IP = $ip \n

Browser Info: $httpagent \n

Referral : $httpref \n

";

 

$from = "From: $email\r\n";

 

require("class.phpmailer.php");

 

$mail = new PHPMailer();

$mail->IsSMTP();                                                  // send via SMTP

$mail->Host    = "mail.myhost.com";                    // SMTP servers

$mail->SMTPAuth = true;                                      // turn on SMTP authentication

$mail->Username = "webmaster@myhost.com";  // SMTP username

$mail->Password = "secret";                                // SMTP password

$mail->From    = $email;

$mail->FromName = $name;

$mail->AddAddress("myname@myhost.com");

$mail->IsHTML(false);                                          // send as HTML

$mail->Subject  =  $subject;

$mail->Body    =  $message;

if(!$mail->Send())

{

  echo "Message was not sent <p>";

  echo "Mailer Error: " . $mail->ErrorInfo;

  exit;

}

 

echo "Message has been sent";

 

$mail->ClearAddresses();

$mail->ClearAttachments();

 

?>

 

<p align="center">

Date: <?php echo $todayis ?>

<b r />

Thank You: <?php echo $name ?>

<b r />

Subject: <?php echo $subject ?>

<b r />

Message: <?php echo $comment ?>

<b r />

<?php echo $ip ?>

 

<b r /><b r />

 

 

Link to comment
https://forums.phpfreaks.com/topic/72680-solved-form-post-help/
Share on other sites

I would use the $_SERVER array instead of getenv() to get those values:

<input type="hidden" name="ip" value="<?php echo $_SERVER['REMOTE_ADDR']?>" />
<input type="hidden" name="httpref" value="<?php echo $_SERVER['HTTP_REFERER'] ?>" />
<input type="hidden" name="httpagent" value="<?php echo $_SERVER['HTTP_USER_AGENT'] ?>" />

 

Be warned that those values can't always be trusted.

 

Ken

Link to comment
https://forums.phpfreaks.com/topic/72680-solved-form-post-help/#findComment-366458
Share on other sites

Thank you.  That corrected the problem.  I have made a note of that for the future.

 

Now, the only thing not working on this form is I am getting a number one (1) ahead of the date for

some reason and I can't quite figure that out, either.  In the date of the message that is emailed to

me (as well as what the customer sees on their screen as the quote of what they sent), this is what

appears:

 

1, October 10, 2007, 17:09 pm [EST]

 

Note the number one right before 'October'.  Can you tell me where that is coming from? 

 

Thank you.

 

Link to comment
https://forums.phpfreaks.com/topic/72680-solved-form-post-help/#findComment-366468
Share on other sites

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.