Forum Moderators: coopster
page with form
<form action="form-confirm.php" method="post" name="Form Inquiry" id="Form Inquiry">
Email: <input name="Email" size="30" />
<input type="submit" value="Submit" name="Submit" />
</form>
php page:
<?
$receiver="my@email.com";
$subject="Form Inquiry";
$header="MIME-Version: 1.0\r\nContent-type: text/plain; charset=iso-8859-1\r\n";
//'add every form element and its value to the email
$body="";
foreach (array_keys($_POST) as $el)
{
if (strcmp("subject",strtolower($el))==0) $subject=$subject." -- ".$_POST[$el];
$value=$_POST[$el];
$display="";
if (is_array($value))
{
foreach ($value as $everydisplay)
{
$display.=$everydisplay." ";
}
}
else
{
$display=$value;
}
$body=$body. $el . ": " . $display . "\r\n";
}
//mail($receiver,$subject,$body);
if ($body!="") mail($receiver,$subject,$body,$header);
?>
emailthispage.php:
<?php
$to = "my@email.com, $email";
$subject = "The Link You Requested";
$message = "not sure how to get the url here;
$from = "$email";
$headers = "From: $from";
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>
------
<form method='post' action='emailthispage.php'>
Email me this page:
<input name='email' type='text' />
<input value="Send Me Link" type='submit' />
</form>
$email = $_REQUEST['email'] ;
Ok, I get this:
URL: http://www.example.com//emailthispage.php
$currentpage='http://'.$_SERVER[HTTP_HOST].'/'.$_SERVER["REQUEST_URI"];
This is displaying the php page and not the html that the form was submitted on.
[edited by: dreamcatcher at 6:50 am (utc) on Oct. 7, 2008]
[edit reason] use example.com. Thanks. [/edit]
Example:
$_POST['email']
If you are passing the form to another page for processing, you need to access the referer, as the page that held the form will be the previous page. I`m assuming the form is actually on the page you want to send the link for and not in a pop up window?
Try:
$currentpage = $_SERVER['HTTP_REFERER'];
Or store the current page in a hidden field as you have done, but use PHP instead of javascript.
$thispage='http://'.$_SERVER[HTTP_HOST].'/'.$_SERVER["REQUEST_URI"];
<input type="hidden" name="page" value="<?php echo $thispage; ?>" />
$message = "URL: ".$_POST['page'];
dc