jayjay76 Posted October 10, 2007 Share Posted October 10, 2007 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       <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">    <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 /> Quote Link to comment https://forums.phpfreaks.com/topic/72680-solved-form-post-help/ Share on other sites More sharing options...
kenrbnsn Posted October 10, 2007 Share Posted October 10, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/72680-solved-form-post-help/#findComment-366458 Share on other sites More sharing options...
jayjay76 Posted October 10, 2007 Author Share Posted October 10, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/72680-solved-form-post-help/#findComment-366468 Share on other sites More sharing options...
marcus Posted October 10, 2007 Share Posted October 10, 2007 I (capital i) Whether or not the date is in daylight saving time 1 if Daylight Saving Time' date=' 0 otherwise.[/quote'] Quote Link to comment https://forums.phpfreaks.com/topic/72680-solved-form-post-help/#findComment-366469 Share on other sites More sharing options...
kenrbnsn Posted October 11, 2007 Share Posted October 11, 2007 You probably want this instead: <?php $todayis = date("l, F j, Y, G:i a"); // the first character is a small L ?> which will produce something like Wednesday, October 10, 2007 .... Ken Quote Link to comment https://forums.phpfreaks.com/topic/72680-solved-form-post-help/#findComment-366669 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.