"forward to a friend" code help????????

I’ve adding the “forward to a friend” code to the following site I’m working on (in the right rail):
http://dealeradvantage.cars.com/bestofda/bestofda8.php

My client is able to receive the email with the actual URL in it that someone is referring them to. BUT when they fill out the form and it is sent via email to another user, the URL of the referral page is not showing up. Any suggestions???

Also, here’s my code:

<!doctype html public "-//w3c//dtd html 3.2//en">

<html>

<head>
<title>Best of Dealer ADvantage from Cars.com<</title>
<meta name="GENERATOR" content="Arachnophilia 4.0">
<meta name="FORMATTER" content="Arachnophilia 4.0">

<style type="text/css">
<!--
A:link
{
	color: #3B0084;
	font-weight: bold;
	text-decoration: none;
}

A:active
{
	color: #3B0084;
	font-weight: bold;
	text-decoration: none;
}

A:visited
{
	color: #3B0084;
	font-weight: bold;
	text-decoration: none;
}

A:hover
{
	color: #3B0084;
	font-weight: bold;
	text-decoration: underline;
}
-->
</style>
</head>

<body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">
<table width="450" cellpadding="0" cellspacing="0" border="0" align="center">
<tr>
<td width="135" bgcolor="#FFFFFF"><img src="images/pixel.gif" alt="pixel" width="130" height="1" align="left" style="margin:0px 0px 15px 0px"></td>
<td bgcolor="#FFFFFF"><img src="images/bda_header.gif" alt="bdaheader" width="180" height="24" border="0" style="margin:5px 0px 10px 0px"></td>
<td width="135" bgcolor="#FFFFFF"><img src="images/pixel.gif" alt="pixel" width="130" height="1" align="right" style="margin:0px 0px 15px 0px"></td>
</tr>
</table>

<?
$status = "OK";
$msg="";
if (!stristr($y_email,"@") OR !stristr($y_email,".")) { // checking your email 
$msg .="Your email address is not correct<BR>"; 
$status= "NOTOK";}

if (strlen($y_name) <2 ) { // checking your name
$msg .="Please enter your name<BR>"; 
$status= "NOTOK";}

if (!stristr($f_email,"@") OR !stristr($f_email,".")) { // checking friends email 
$msg .="Your friend's email address is not correct<BR>"; 
$status= "NOTOK";}

if (strlen($f_name) <2 ) { // checking freinds name
$msg .="Please enter your friend's name<BR>"; 
$status= "NOTOK";}

if($status=="OK"){ // all validation passed
/////////// Sending the message starts here //////////////
$ref=@$HTTP_REFERER; 
/////Message at the top of the page showing the url////
$header_message = "Hi $f_name, n Your friend $y_name is requesting you visit a Best of DealerADvantage page at n $ref n";
/// Body message prepared with the message entered by the user ////
$body_message = $header_message. "n $y_name also sent you the following message:n $y_msg";

//// Mail posting part starts here /////////

$headers="";
//$headers = "Content-Type: text/html; charset=iso-8859-1n".$headers; 
// Un comment the above line to send mail in html format
$headers4=$y_email;         // Change this to change from address
$headers.="Reply-to: $headers4n";
$headers .= "From: $headers4n"; 
$headers .= "Errors-to: $headers4n"; 

$subject="Best of Dealer ADvantage from Cars.com";

mail($f_email,$subject,$body_message,$headers);

////// Mail posting ends here ///////////
echo "<center><font face='Verdana' size='2' color=#3B0084>Thank you for sharing the news from the Best of DealerADvantage.<br /> Your message has been sent to <b>$f_name</b></font></center>";
//////////// Sending the message ends here /////////////
}else{// display the error message
echo "<center><font face='Verdana' size='2' color=red>$msg</font></center>";
}
?>

</body>

</html>
:)

ADMIN EDIT: Added the bbcode tags for CODE to make it more readable. Refer to http://phphelp.com/forums/viewtopic.php?t=2752

First of all, next time could you please narrow the code down to the needed parts. For example the STYLE information is not needed at all. If you can narrow other information down, that would be helpful too.

Any way, you have a line like
$ref=@$HTTP_REFERER;

This could be part of the problem…

First of all why are you prefacing it with the @ sign? You do know that it will suppress any errors that line may cause?

either way, that is “Old Style”. If you have PHP set up in a more secure way, then you have REGISTER_GLOBALS =Off which means that the format you are using won’t work (and I believe it’s deprecated anyway). You should use the SUPER GLOBAL of $_POST[‘HTTP_REFERER’] instead. Also to minimize the potential errors you could redo that line as follows:

$ref=!empty ($_POST[‘HTTP_REFERER’]) ? $_POST[‘HTTP_REFERER’] : ‘http://dealeradvantage.cars.com/’ ;

This will see if a referral URL is passed. If it is it will assign it to $ref. If not then it will just send the Main hope page of the domain as $ref

You can check out http://us3.php.net/manual/en/language.o … arison.php under the Ternary Operator for info on using this syntax.

Thanks! I’ll try this and see if it works.

Thanks for the reply!

I tried:
$ref=!empty ($_POST[‘HTTP_REFERER’]) ? $_POST[‘HTTP_REFERER’] : ‘http://dealeradvantage.cars.com/’ ;
and all i received was http://dealeradvantage.cars.com NOT the actual link to the referal page.

But I had previously been using the original code with the "$ref=@$HTTP_REFERER; " and it worked in most email browsers. I just have one set of clients (all using the same email browsers and servers) that can receive the referring URL in their email put when they try to fill out the form to refer the page link to a friend I do not get any URL in the email I receive from them???

I am sorry I presented it wrong… It’s not a POSTED variable it’s a SERVER variable. It should be as follows:

$ref=!empty ($_SERVER[‘HTTP_REFERER’]) ? $_SERVER[‘HTTP_REFERER’] : ‘http://dealeradvantage.cars.com/’ ;

Sorry about that…

this didn’t grab the actual URL of the page the user was on. it just sent the homepage url to the user’s email account. Any other suggestions??

Thanks!

Well the HTTP_REFERER is actually the page that referred you to the page you are currently on. So if you clicked a link from GOOGLE that took you to the page that the form was submitted to, the HTTP_REFERER would be the google.com page.

You could consider using the PHP_SELF instead of the HTTP_REFERER (also a SERVER super global). That will give the the URL of the page that you are currently on. This all depends on how you process the pages and the form data.

Also could you let us know the following:
Version of O/S the webserver is running on.
Version of Webserver software.
Version of PHP

If you are always getting the default domain name when using the ternary function :
$ref=!empty ($_SERVER[‘HTTP_REFERER’]) ? $_SERVER[‘HTTP_REFERER’] : ‘http://dealeradvantage.cars.com/’ ;
, then something is not passing the data as it should be

That function could be re-written as

// checks to see if a value is passed in the HTTP_REFERER Super global 
if (!empty ($_SERVER['HTTP_REFERER']) {
     // if a value is passed... assign it to $ref
     $ref= $_SERVER['HTTP_REFERER'] ; 
} else {
     // if a value is NOT passed, then assign it the default domain value instead
     $ref='http://dealeradvantage.cars.com/' ;
}

Either way… if all you get is the default domain entry… something is not being passed in the super global. It might be a version issue (which iw why I asked that question.)

so if i use the code you supplied it should look like this:

<?
$status = "OK";
$msg="";
if (!stristr($y_email,"@") OR !stristr($y_email,".")) { // checking your email 
$msg .="Your email address is not correct<BR>"; 
$status= "NOTOK";}

if (strlen($y_name) <2 ) { // checking your name
$msg .="Please enter your name<BR>"; 
$status= "NOTOK";}

if (!stristr($f_email,"@") OR !stristr($f_email,".")) { // checking friends email 
$msg .="Your friend's email address is not correct<BR>"; 
$status= "NOTOK";}

if (strlen($f_name) <2 ) { // checking freinds name
$msg .="Please enter your friend's name<BR>"; 
$status= "NOTOK";}

if($status=="OK"){ // all validation passed
/////////// Sending the message starts here //////////////
if (!empty ($_SERVER['HTTP_REFERER']) {
     // if a value is passed... assign it to $ref
     $ref= $_SERVER['HTTP_REFERER'] ;
} else {
     // if a value is NOT passed, then assign it the default domain value instead
     $ref='http://dealeradvantage.cars.com/' ;
} 
/////Message at the top of the page showing the url////
$header_message = "Hi $f_name, n Your friend $y_name is requesting you visit a Best of DealerADvantage page at n $ref n";
/// Body message prepared with the message entered by the user ////
$body_message = $header_message. "n $y_name also sent you the following message:n $y_msg";

//// Mail posting part starts here /////////

$headers="";
//$headers = "Content-Type: text/html; charset=iso-8859-1n".$headers; 
// Un comment the above line to send mail in html format
$headers4=$y_email;         // Change this to change from address
$headers.="Reply-to: $headers4n";
$headers .= "From: $headers4n"; 
$headers .= "Errors-to: $headers4n"; 

$subject="Best of Dealer ADvantage from Cars.com";

mail($f_email,$subject,$body_message,$headers);

////// Mail posting ends here ///////////
echo "<center><font face='Verdana' size='2' color=#3B0084>Thank you for sharing the news from the Best of DealerADvantage.<br /> Your message has been sent to <b>$f_name</b></font></center>";
//////////// Sending the message ends here /////////////
}else{// display the error message
echo "<center><font face='Verdana' size='2' color=red>$msg</font></center>";
}
?>

ADMIN EDIT: Added the bbcode tags for CODE to make it more readable. Refer to http://phphelp.com/forums/viewtopic.php?t=2752

Whether you user the super global $_SERVER[‘HTTP_REFERER’] (more secure - used when REGISTER_GLOBALS are ON in your php.ini file but will work if it is off) or you use $HTTP_REFERER (less secure and will only work when your REGISTER_GLOBALS are off) if you are only getting the default domain (form the ELSE part of the code) then that means something is not passing the referer information. (or not always.)

Here’s the server info:
Version of O/S the webserver is running on:Windows_NT
Version of Webserver software: Microsoft-IIS/6.0
Version of PHP: 4.4.0

Again, this script works with almost every email I’ve sent it to. It just doesn’t work for a specific client. i.e. the URL never shows up in their email. Could this have to do with the browser and version they’re using for the Internet? Perhaps their browser is not collecting the URL to be sent via email?

Thanks!

Sponsor our Newsletter | Privacy Policy | Terms of Service