PDA

View Full Version : Recommend us to a friend - email takes friend to wrong page



Steph84
12 Sep 2010, 10:28 AM
Hello - I know very little PHP/Javascript so I am having a problem that I hope is easily fixable.

I installed a "recommend to a friend" tool to my website and have managed to solve a few issues I have had with it, however there is one issue I can't work out how to solve.

The email that is sent to the 'friend' displays a link to the /siterecommender/recommend.popup.php page (that sent the email). I want it to take them to the home page instead.

The php is as follows:


$sitename = '1-2-1 Music Tuition'; // Name of your site.

$url = $_SERVER['HTTP_REFERER']; // Web address for your site.

$webmasterEmail = 'info@1-2-1music.co.uk'; // 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 = 4; // Number of recipient email address fields to be displayed.

$emailsubject = 'Music tuition recommendation from [name] ([email])'; //Email subject line.

$emailmessage = "Hello

[name] thought you would like to visit the following site:

[url]

1-2-1 Music Tuition provide acoustic and electric guitar, bass guitar and drum tuition at competitive rates. They are based in a professional recording studio in Sheffield city centre. New pupils can get their first lesson for only £5. See their website for more information."; // Message in email body.

$mailsent = false;
$errormessages = array();
$errorfields = array();

if(count($_POST) > 0) {
if(get_magic_quotes_gpc()) $_POST = strip_magic_quotes($_POST);

if(empty($_POST['name'])) {
$errormessages[] = 'Please enter your name.';
$errorfields[] = 'name';
}

if(empty($_POST['email'])) {
$errormessages[] = 'Please enter your email address.';
$errorfields[] = 'email';
} else {
if(!eregi("^[a-z0-9\._-]+@+[a-z0-9\._-]+\.+[a-z]{2,3}$", $_POST['email'])) {
$errormessages[] = 'Please enter a proper email address for yourself.';
$errorfields[] = 'email';
}
}

for($i=1, $count=count($_POST['to']); $i<=$count; $i++) {
if(empty($_POST['to'][$i])) unset($_POST['to'][$i]);
}

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 .= "\r\n\n" .
$_POST['message'] .
"\n\n\n\nNote: This message was not sent unsolicited. It was sent through a form located at $url. " .
"If you believe this message was received on error, please disregard it.";
$emailheader = "From: " . $_POST['email'] . "\r\n" .
"Reply-To: " . $_POST['email'] . "\r\n" .
"X-Mailer: GateQuest php Site Recommender\r\n";

$sent = array();
foreach($_POST['to'] as $key=>$value) {
if(mail($value, $emailsubject, $emailmessage, $emailheader)) {
$sent[] = $value;
}
}
$failed = array_diff($_POST['to'], $sent);
$mailsent = true;

if($receiveNotifications) {
$subject = 'Someone recommended your site';
$message = 'This is a message to tell you that ' . $_POST['name'] . ' (' . $_POST['email'] .')' .
' sent a website recommendation to ' . implode(', ', $sent) .
"\n\nMessage: " . $_POST['message'];
$headers = 'From: ' . $webmasterEmail . "\r\n" .
'X-Mailer: GateQuest php Site Recommender';
@mail($webmasterEmail, $subject, $message, $headers);
}
}
}

?>

(there is more code that follows but it is to do with the form that sends the email, not the email itself).

It's clearly something to do with $url but beyond that I am not sure. How do I get the email to show a link to the home page, rather than the page that sent the email?

Any help will be much appreciated.

Thanks. Steph :)