I have thsi script and I am trying to pass the variables to a form ... and have it email them but for some reason its not working ... can anyone offer a reason why it might not be or what I might do to fix it ?

This is the form part

<form method="post" action="sendmail.php">
<!-- DO NOT change ANY of the php sections -->
<?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 ?>" />

and this is the part of the sendmail script that sends it is a mail ...

$todayis = date("l, F j, Y, g:i a") ;
 
$subject = $attn; 

$notes = stripcslashes($notes); 

$message = " $todayis [EST] \n
Message: $notes \n 
From: $visitor ($visitormail)\n
Additional Info : IP = $ip \n
Browser Info: $httpagent \n
Referral : $httpref \n
";

but instead of getting the ip and browser info and the referrer ... all I get is this

Additional Info : IP = <?php echo $ipi ?>

Browser Info: <?php echo $httpagenti ?>

Referral : <?php echo $httprefi ?>

instead of the actual output ? am I missing something ?


Anyone ? thanks for your input / help

IWFM (It Works For Me). :)

Therefore, if forced to guess, I would say your web server does not grok PHP or it doesn't know that it should be speaking PHP:

  • PHP is not installed,
  • PHP is not configured, or
  • your web browser is not configured to process your files through PHP (perhaps your file extensions are wrong).

Well PHP is installed on my server and I use it with all sorts of other scripts ... so why would this one not work ?

it is sending to an email but the contents of the email do not pass the results ... its very odd

Well PHP is installed on my server and I use it with all sorts of other scripts ... so why would this one not work ?

it is sending to an email but the contents of the email do not pass the results ... its very odd

Duh. My bad. IWFM *with a few additions*. I used (as 'a.php')

<form method="post" action="b.php">
<!-- DO NOT change ANY of the php sections -->
<?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 ?>" />
<input type="submit" name="submit" value="submit" />
</form>

and (as 'b.php')

<?php
print("<pre>");
print_r($_POST);
print ("</pre>");

$ip = $_POST['ip'];
$httpagent = $_POST['httpagent'];
$httpref = $_POST['httpref'];

$todayis = date("l, F j, Y, g:i a") ;
 
$subject = $attn; 

$notes = stripcslashes($notes); 

$message = " $todayis [EST] \n
Message: $notes \n 
From: $visitor ($visitormail)\n
Additional Info : IP = $ip \n
Browser Info: $httpagent \n
Referral : $httpref \n
";

print"<pre>".$message."</pre>";
?>

Are you fetching the values out of the $_POST array? And are you mindful of accessible scopes?

Remember that every request of a web server is a new instance with new environment; they have no knowledge of any other web page or variables.

I have thsi script and I am trying to pass the variables to a form ... and have it email them but for some reason its not working ... can anyone offer a reason why it might not be or what I might do to fix it ?

This is the form part

<form method="post" action="sendmail.php">
<!-- DO NOT change ANY of the php sections -->
<?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 ?>" />

and this is the part of the sendmail script that sends it is a mail ...

$todayis = date("l, F j, Y, g:i a") ;
 
$subject = $attn; 

$notes = stripcslashes($notes); 

$message = " $todayis [EST] \n
Message: $notes \n 
From: $visitor ($visitormail)\n
Additional Info : IP = $ip \n
Browser Info: $httpagent \n
Referral : $httpref \n
";

but instead of getting the ip and browser info and the referrer ... all I get is this

Additional Info : IP = <?php echo $ipi ?>

Browser Info: <?php echo $httpagenti ?>

Referral : <?php echo $httprefi ?>

instead of the actual output ? am I missing something ?


Anyone ? thanks for your input / help

If your form page saved as a PHP file or HTML file? It looks like the form is not being evaluated as PHP.

If your form page saved as a PHP file or HTML file? It looks like the form is not being evaluated as PHP.

That was the fix I forgot that I need to run the file as a .php

??? however is there anything I can add to the file and keep it as an HTML ... and not have to change it to a PHP ?

Just curious if this can be done inside a html page with telling the server to run the form part as PHP ?

Thanks Digital Ether for the HELP and resolution ...

I was wondering one last thing with my scripting maybe you can help me ... when I submit the form it changes to another page to thank the user for thier message then has a link to go back to the page you want them to return to ... is there any way of making the TY message open in a POP UP box instead and then clearing the form so when they close the pop up they have not left your website ?

<p align="center">
Date: <?php echo $todayis ?> 
<br />
Thank You : <?php echo $visitor ?> ( <?php echo $visitormail ?> ) 
<br />

Message:<br /> 
<?php $notesout = str_replace("\r", "<br/>", $notes); 
echo $notesout; ?> 
<br />
<?php echo $ip ?> 

<br /><br />
<a href="contact.html"> Return To WMAR </a> 
</p>

or can it be done with this one instead ?

<?php 
$EmailFrom = Trim(stripslashes($_POST['EmailFrom'])); 
$Name = Trim(stripslashes($_POST['Name'])); 
$Comments = Trim(stripslashes($_POST['Comments'])); 

// validation
$validationOK=true;
if (Trim($EmailFrom)=="") $validationOK=false;
if (Trim($Name)=="") $validationOK=false;
if (Trim($Comments)=="") $validationOK=false;
if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
  exit;
}

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $EmailFrom;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Comments;
$Body .= "\n";

// send email 
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

// redirect to success page 
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=contact.html\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
}
?>

can either of those be made to open in a popup ? instead of leaving the submit page ?

Thanks again all for your HELP and support its REALLY greatly appreciated

You can use the target attribute. (not valid in strict doctype however)

eg:

<form target="_blank" method="post" action="sendmail.php">

However, you cannot control the new window. If you want to do that you will need to use JavaScript. You'll need JavaScript to clear the form also.

You can use the target attribute. (not valid in strict doctype however)

eg:

<form target="_blank" method="post" action="sendmail.php">

However, you cannot control the new window. If you want to do that you will need to use JavaScript. You'll need JavaScript to clear the form also.

any direction on the javascript part ? any ideas on where I can research to get info on doing this I am not against learning just need to be pointed in the direction of where to learn ... it would be nice to do both ... control the popup and clear the form if possible ...

thank you again for your help and assistance

is the form in a .php page? sorry but I didn't read all the posts, just the first one.

commented: Maybe you should have taken the time to read the other posts. -2

w3schools.com is pretty good for learning JS: http://w3schools.com/js/default.asp

You'll wan to understand the DOM and DOM selectors. This will allow you to select the form elements, and clear them.

clearing a single form element named "test".

forms[0].test.value = '';

I'm assuming the form is the first one and reference it using forms[0]. OR you can reference the form by name:

forms['formname'].test.value = '';

To make your coding easier, I'd suggest using a library such a JQuery, or MooTools.

This gives you the ability to use CSS selectors, which makes selecting elements on the page easier.
http://api.jquery.com/category/selectors/

selecting the element named test would be:

$('input[name=test]').attr('value', '');

The other benefit of using the library is that you can get very specific help in the forum. http://forum.jquery.com/

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.