Forum Moderators: coopster
Just put a link to it from any page and it takes that from the referer and stuffs it in
<?php
$page_title = "Send To Friend";
$error_variables = false;
if ($_SERVER['REQUEST_METHOD'] == "POST"){
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
if (isset($_POST['ref'])) {
$ref = $_POST['ref'];
}
$value = $email;
$pattern = "/^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+/";
if(!preg_match($pattern, $value))
{
$error_variables = true;
$errors["email"] = true;
}
if (!$error_variables){
$message_full = "$message\n";
$my_email = "$email";
mail("$my_email", $subject, $message_full, "From: feedback@url.com");
print "<p>Your mail has been sent</p>";
}
else
{
?>
<p>There is a problem with the data you have used. Please check and send again.</p>
<form method="post" action="send_to_friend.php" class="formadd">
<table width="100%">
<tr>
<td width="21%"><b>The link you are sending</b></td>
<td width="2%"> </td>
<td width="77%">
<?php
if (strlen($ref) >50) {
$refLen = strlen($ref);
for ($i = 0, $i < $refLen; $i = $i + 50;) {
echo substr($ref, $i, $i + 50) . '<br />';
}
} else {
print "$ref";
}
?>
</td>
</tr>
<tr>
<td width="21%"><b>Your Friends Email</b></td>
<td width="2%"> </td>
<td width="77%">
<input type="text" name="email" value="<?php echo $email?>" class="term" size="50">
<?php
//show bold for error
if ($errors["email"]){
print '<b><font color="#FF0000">Have you missed the @ symbol?</font></b>';
}
?>
</td>
</tr>
<tr>
<td width="21%"><b>Subject</b></td>
<td width="2%"> </td>
<td width="77%">
<input type="text" name="subject" value="<?php echo $subject?>" class="term" size="50">
<?php
//show bold for error
if (!isset($errors['subject']) ¦¦ $errors["subject"]){
print "<b><font color=\"#FF0000\">Please Type a Subject</font></b>";
}
?>
</td>
</tr>
<tr>
<td width="21%" align="left" valign="top"><b>Message</b></td>
<td width="2%"> </td>
<td width="77%">
<textarea name="message" cols="50" rows="10"><?php echo $message?></textarea>
</td>
</tr>
<tr>
<td width="21%"> </td>
<td width="2%"> </td>
<td width="77%"> </td>
</tr>
</table>
<p>
<input type="submit" value="Send Email" class="button">
</p>
</form>
<?php
};
}
else
{
?>
<form method="post" action="send_to_friend.php">
<div id="search">
<table width="100%">
<tr>
<td width="21%"><b>The link you are sending</b></td>
<td width="2%"> </td>
<td width="77%">
<?php
$ref= $_SERVER["HTTP_REFERER"];
if (strlen($ref) >50) {
$refLen = strlen($ref);
for ($i = 0, $i < $refLen; $i = $i;) {
echo substr($ref, $i, $i + 50) . '<br />';
$i = $i + 50;
}
} else {
print "$ref";
}
?>
</td>
</tr>
<tr>
<td width="21%"><b>Your Friends Email</b></td>
<td width="2%"> </td>
<td width="77%">
<input type="text" name="email" value="" class="term" size="50">
</td>
</tr>
<tr>
<td width="21%"><b>Subject</b></td>
<td width="2%"> </td>
<td width="77%">
<input type="text" name="subject" value="" class="term" size="50">
</td>
</tr>
<tr>
<td width="21%" align="left" valign="top"><b>Message</b></td>
<td width="2%"> </td>
<td width="77%">
<textarea name="message" cols="50" rows="10">Hello, I found this webpage and thought that it would interest you.
<?php
print "$ref";
?>
Thanks
</textarea>
</td>
</tr>
<tr>
<td width="21%"> </td>
<td width="2%"> </td>
<td width="77%">
<input type="hidden" name="ref" value="<?php echo $ref;?>">
</td>
</tr>
</table>
<p>
<input type="submit" value="Send Email" class="button">
</p>
</div>
</form>
<?php
}
?>
friend.php?referer=$_SERVER['REQUEST_URI']
then in the script you would change
$ref=$_SERVER['HTTP_REFERER'] for
$ref=$_GET['referer']
not sure if that helps or hurts ;-)