I link to a "tell a friend" or "share page" script by using this link which grabs the url of the page the visitor is on (the original script uses a refferer which is often blocked.)
Code:
<a href="http://www.mysite.com/friend.php?sharepage=http://www.mysite.com<?php echo $_SERVER['REQUEST_URI']; ?>">Share this page</a>
In my friend script, I use GET to retrive the url to be shared then I assign it to $url2. The user then enters their info and the info of the people to share the page with. When they hit submit, the form posts to itself and $url2 is passed as a hidden variable "share_url" which I assign to $url3 for printing in the email.
My problem is the shared address is cutoff at the first "&" if I have an address like: "http://www.mysite.com/hello.php?page_id=12&topic=news&date=apr09" All I would get is "http://www.mysite.com/hello.php?page_id=12" What am I doing wrong?
This is my friend.php script:
PHP Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
if(empty($_POST['to'])) {
$errormessages[] = 'Please enter at least one friend\'s email address.';
$errorfields[] = 'to[1]';
} else {
foreach($_POST['to'] as $key=>$value) {
if(!empty($value)) {
if(!eregi("^[a-z0-9\._-]+@+[a-z0-9\._-]+\.+[a-z]{2,3}$", $value)) {
$errormessages[] = 'Please enter email address #' . $key . ' proper.';
$errorfields[] = "to[$key]";
}
}
}
}
// Now if there are no errors, send the message.
if(empty($errormessages)) {
$emailsubject = str_replace('[name]', $_POST['name'], $emailsubject);
$emailsubject = str_replace('[email]', $_POST['email'], $emailsubject);
$emailmessage = str_replace('[name]', $_POST['name'], $emailmessage);
$emailmessage = str_replace('[url]', $url, $emailmessage);
//$emailmessage = str_replace('[share_url]', $_REQUEST['share_url'], $emailmessage);
$emailmessage .= "\r\n\n" .
$_POST['message'] .
"\n\n\n\nNote: This message was not sent unsolicited. It was sent through a form located at the website: $url. ";
$emailheader = "From: " . $_POST['email'] . "\r\n" .
"Reply-To: " . $_POST['email'] . "\r\n" .
"X-Mailer: Big Lick Media - php Site Recommender\r\n";
The problem you are having is the GET arguments in the shared site URL.
The way you have it written, they are treated as separate $_GET variables.
You need to change the question mark (?) and the and signs (&) to something other than their literal values.
In this example I have the code change the question mark (?) with a star (*) and the and signs (&) with double stars (**).
$url = 'http://www.mysite.com'; // Web address for your site.
$url2 = empty($_GET['sharepage'])?"":$_GET['sharepage']; // Actual page to be sent $url2 = str_replace("*","?",str_replace("**","&",$url2)); $url3 = empty($_POST['share_url'])?"":$_POST['share_url']; // url was passed as hidden variable
$webmasterEmail = 'me@mysite.com'; // Your email address.
$receiveNotifications = 1; // 0=no, 1=yes. If yes, you will be notified of the recipients and the message.
$errorstyleclass = 'error'; // The class that specifies the CSS error color.
$numberofrecipients = 10; // Number of recipient email address fields to be displayed.
if(empty($_POST['to'])) { $errormessages[] = 'Please enter at least one friend\'s email address.'; $errorfields[] = 'to[1]'; } else { foreach($_POST['to'] as $key=>$value) { if(!empty($value)) { if(!eregi("^[a-z0-9\._-]+@+[a-z0-9\._-]+\.+[a-z]{2,3}$", $value)) { $errormessages[] = 'Please enter email address #' . $key . ' proper.'; $errorfields[] = "to[$key]"; } } } }
// Now if there are no errors, send the message. if(empty($errormessages)) { $emailsubject = str_replace('[name]', $_POST['name'], $emailsubject); $emailsubject = str_replace('[email]', $_POST['email'], $emailsubject); $emailmessage = str_replace('[name]', $_POST['name'], $emailmessage); $emailmessage = str_replace('[url]', $url, $emailmessage); //$emailmessage = str_replace('[share_url]', $_REQUEST['share_url'], $emailmessage); $emailmessage .= "\r\n\n" . $_POST['message'] . "\n\n\n\nNote: This message was not sent unsolicited. It was sent through a form located at the website: $url. ";
$emailheader = "From: " . $_POST['email'] . "\r\n" . "Reply-To: " . $_POST['email'] . "\r\n" . "X-Mailer: Big Lick Media - php Site Recommender\r\n";