Page 1 of 1

Grabbing a URL via Popup

Posted: Thu Aug 12, 2010 6:29 pm
by rohan.weston
Hi guys. I'm very new to PHP, and I'm trying to create a simple mail script.

Mail a friend
A user will click an image on the site which will open a pop up box. They input their name and the email of the friend that they want to send the current URL to. The email will send the current URL via email and display a confirmation message once it has sent successfully.
The friend will receive an email with a link to the URL.

The problem
The email part works fine, it's the URL in the message that is the issue. When the user clicks the 'Email a friend' it opens a popup box - which is where the URL is being grabbed from and emailed.
Is there a way to grab the URL from the page before the popup?

Here is my (rather amateur) code. Also, feel free to let me know if I can make improvements to it if anything seems a bit strange!

The popup link:
<a onclick="window.open(this.href,'win2','width=400,height=350,menubar=yes,resizable=yes'); return false;" title="E-mail" href="mailform/form.html">Send to a friend</a>

The popup form:

<html>
<body>
<form method="post" action="code.php">
Friends Email: <input name="email" type="text" /><br />
Your Name: <input name="name" type="text" /><br />
<input type="submit" />
</form>
</body>
</html>


The PHP code:

Code: Select all

<?php
// Declaring Variables
    $email = $_REQUEST['email'] ;
    $name = $_REQUEST['name'];
    $geturl = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
    $message = "Hello. $name has suggested a page for you to view on our website. Please click the following link: $geturl";

// Email Settings
    mail( $email, "Send page to a friend",
        $message, "From: Timaru District Council" );
    header( "Location: http://www.c4clever.com/sandbox/mailform/sent.html" ); // Confirmation page (Change this to appropriate URL)
?>
Feel free to test it out if you want to (http://www.c4clever.com/sandbox)


Looking forward to replies, thanks in advance!