/    Sign up×
Community /Pin to ProfileBookmark

PHP Recommender Referer

Hi, I’m learning PHP the ‘proper’ way i.e. experimenting and getting lost a lot. And I’m stuck. I have a recommender script below, but instead of the fixed url which is useless for a popup window, I’d like to add a referrer URL to the email. I’ve tried a few ways none of which work because by the time the email is in someones inbox the referrer URL has turned into the page that sent the email.
I’m basically clueless so if this is a lot to ask I’m sorry, but is there a very simple way to include a proper referrer into the code below that will be correct by the time it arrives in the email?

Many thanks,

[code=php]

$sitename = ‘XXXXXXX’;

$url = ‘http://www.XXXXXX.co.uk’;

$webmasterEmail = ‘[email protected]’;

$receiveNotifications = 1;

$errorstyleclass = ‘error’;

$numberofrecipients = 3;

$emailsubject = ‘Website Recommendation from [name] ([email])’;

$emailmessage = “Hello,nr[name] thought you would like to visit the following site: [url]”;

$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 valid 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[] = ‘Email address ‘ . $key . ‘ is not valid.’;
$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 .= “rnn” .
$_POST[‘message’] .
“nnnnNote: This message was not sent unsolicited. It was sent through a recommendation form at $url. ” .
“If this message was received in error, please disregard.”;
$emailheader = “From: ” . $_POST[’email’] . “rn” .
“Reply-To: ” . $_POST[’email’] . “rn” .
“X-Mailer: XXXXX Recommenderrn”;

$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 XXXXX’;
$message = ‘This is a message to tell you that ‘ . $_POST[‘name’] . ‘ (‘ . $_POST[’email’] .’)’ .
‘ sent a website recommendation to ‘ . implode(‘, ‘, $sent) .
“nnMessage: ” . $_POST[‘message’];
$headers = ‘From: ‘ . $webmasterEmail . “rn” .
‘X-Mailer: BPIT Consulting Recommender’;
@mail($webmasterEmail, $subject, $message, $headers);
}
}
}

?>

<?php
if($mailsent) {
echo empty($sent) ? ” : ‘<p>Message was successfully sent to <font color=#fe4347>’ . implode(‘, ‘, $sent) . ‘</font></p>’;
echo empty($failed) ? ” : ‘<p>Message was NOT successfully sent to ‘ . implode(‘, ‘, $failed) . ‘<br />Please try again later!</p>’;
echo ‘<p>Thank you for recommending ‘ , $sitename , ‘</p>’;
} else {
if(count($_POST) > 0 && !empty($errormessages)) {
echo ‘<table><tr><td><span class=”‘ , $errorstyleclass , ‘”>’;
echo ‘The following error(s) occured:<br />’;
foreach($errormessages as $value) {
echo ‘ &nbsp; &nbsp; &raquo; ‘ ,$value , ‘<br />’;
}
echo ‘</span><br /></td></tr></table>’;
}
?>
[/code]

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@scragarFeb 09.2005 — use PHP 'refer' from the PHP server vars.
Copy linkTweet thisAlerts:
@TygerTygerauthorFeb 09.2005 — Hm? I wasn't kidding when I said I was clueless.
Copy linkTweet thisAlerts:
@scragarFeb 10.2005 — for PHP 4.1 or lower

$HTTP_SERVER_VARS['HTTP_REFERER']

or

$_SERVER['HTTP_REFERER']

in all newer versions.
×

Success!

Help @TygerTyger spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...