Jump to content

Recommended Posts

Hi I am new to PHP. I am trying to customize some Tell a Friend code I found. Is there an alternative to $your_domian_name. Instead of taking the user to shop-orthomolecular.com I want to be able to take the user to the actual page the another user is recommending

 

Here is the code:

 

$your_domian_name = "shop-orthomolecular.com";

//edit what you want your vistors to see in their email here

$subject = $from_name." sent you an invitation to $your_domian_name";

$your_message = "Hi!\r\n";

$your_message.= ucfirst($from_name);

$your_message.= " wants you to check out $your_domian_name. This email was forwarded using a tell-a-friend feature. In cases of abuse, contact webmaster@doctorschoice.org\r\n\r\n\r\n\r\n";

 

$your_message.= "Sender's Message:\n\r";

 

 

Link to comment
https://forums.phpfreaks.com/topic/126790-tell-a-friend-feature-help/
Share on other sites

$_SERVER['REQUEST_URI']  almost works but it takes me to the page that the form is on (tell_a_friend.php) and not the previous one that the user would click on to get to the form to pop up. That is the page they will be recommending. Any Ideas? Can I add anything to $_SERVER['REQUEST_URI'] to make it go to the previous URL?

Well, I'm not sure since you are using a pop up, but this is somewhat what I have done (it might help you somehow):

 

 

mypage.php

<?php

require("tell_a_friend.php"); // This way, the URL you get in "tell_a_friend.php" will always be the one the user is recommending.

?>

 

 

tell_a_friend.php

<?php

$url = "http://www." . $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];

// Your form here

?>

 

Just a thought if you don't necessarily want to use pop ups.

So am I putting a link on mypage.php to tell_a_friend.php? or this code on the same page?

 

I really am a newbie

 

- Open the source of the page where you want the tell a friend script to appear (I'll just call it "example.php").

- Find the placing in your HTML code where you want it to appear (or just place the line below anywhere and move it around later if you're not too experienced with the HTML basics either)

- Insert the following line:

 

<?php require("tell_a_friend.php"); ?>

 

- Save & close your file.

- Put this code at the top of "tell_a_friend.php":

 

<?php $url = "http://www." . $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"]; ?>

 

- Put your form code (text fields, buttons, etc.) and the PHP code that sends the mail in "tell_a_friend.php"

- Save & close "tell_a_friend.php".

- Upload "example.php" & "tell_a_friend.php" to your webserver and make sure that they are in the same folder.

 

If you encounter any problems or have any more questions, just ask. :)

I got it to work for a php page but all the pages I want to use the code on are html pages. I am trying to use a link that opens up a pop up that is tell_a_friend.php. I want a user to send an email that tells his/her friend about the exact page that the user clicked on the tell a friend link. Thanks for the help.

 

I will just paste all my code and maybe someone will be able to show me where I am going wrong.

 

here it is. Any help would be appreciated.

 

This is the code for one of the html pages that will have the link to "tell_a_friend.php"

 

<h2> Alphabetical: Ortho Molecular - M</h2>
<table width="731" border="0">
  <tr> 
    <td width="422" height="78" valign="top"> 
      <p><b></b></p>
      <hr>
      <p><b><font color="#CC6600">Alphabetical Search - Ortho Molecular Products</font></b></p>
      <p><b><a href="/store/ortho_4-5.html">4</a> <a href="/store/ortho_4-5.html">5</a></b> 
        <b><a href="/store/ortho_a.html">A</a> <a href="/store/ortho_b.html">B</a> 
        <a href="/store/ortho_c.html">C</a> <a href="/store/ortho_d.html">D</a> 
        <a href="/store/ortho_e.html">E</a> <a href="/store/ortho_f.html">F</a> 
        <a href="/store/ortho_g-h-i.html">G</a> <a href="/store/ortho_g-h-i.html">H</a> 
        <a href="/store/ortho_g-h-i.html">I</a> J 
<a href="/store/ortho_k.html">K</a> 
        <a href="/store/ortho_l.html">L</a> <a href="/store/ortho_m.html">M</a> 
        <a href="/store/ortho_n.html">N</a> <a href="/store/ortho_o.html">O</a> 
        <a href="/store/ortho_p.html">P</a> <a href="/store/ortho_q-r.html">Q</a> 
        <a href="/store/ortho_q-r.html">R</a> <a href="/store/ortho_s.html">S</a> 
        <a href="/store/ortho_t.html">T</a> <a href="/store/ortho_u-v.html">U</a> 
        <a href="/store/ortho_u-v.html">V</a> W X Y 
        Z<BR>
        <BR>
        </b></p>
      <hr>
      <p><b> </b></p>
    </td>
    <td width="292" valign="top"><a href="javascript:popup()"><img src="http://www.shop-orthomolecular.com/store/media/artimages/TellAFriend.gif" alt="Orthomolecular, Tell A Friend" width="174" height="43" border="0" ></a> <td width="3"></td>
  </tr>
</table>

 

 

 

And here is tell_a_friend.php:

 

<?php

/******************************************************************************
     * Tell A Friend Script: 
 * This script allows your visitors to sent invitation to their friends via email to visit your site.
 *
 * Usage: 
 * The script comes with three files tell_a_friend.php, thankyou.html and install.txt
 * You're NOT allowed to redistribute or sell this script.
 * You are allowed to modify this script for your own personal use.	 
 * Please see install.txt attached in the zip for installation instructions.
 *
 * Notes:
 * If you like this script or used it for your website or project.
 * Please remember too link back to www.php-learn-it.com. 
 * Your help is always appreciated.
 *
 * author: webdev (php-learn-it.com (or phplearnit.com)
 * Visit www.php-learn-it.com (or www.phplearnit.com) for more script and tutorials on PHP.
 *****************************************************************************/

//minimum characters allowed in the message box
$msg_min_chars = "10";

//maximum characters allowed in the message box
$msg_max_chars = "250";

$errors = array();




function validate_form_items()
{
   global $msg_min_chars, $msg_max_chars;
   $msg_chars = "{".$msg_min_chars.",".$msg_max_chars."}";

   $form_items = array(
   
   
   
	   "name"  => array(
					   "regex" => "/^([a-zA-Z '-]+)$/",
					   "error" => "Your name appears to be in improper format",
					   ),
		"email" => array(
					   "regex" =>
						"/^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$/",
					   "error" => "email address is invalid",
					   ),
	   "message" => array(
					   "regex" => "/.*/",
					   "error" => "Your message is either too short or exceeds $msg_max_chars characters",
					   ),
   );

   global $errors;

	if(!preg_match($form_items["name"]["regex"], $_POST["your_name"]))
		$errors[] = $form_items["name"]["error"];

	if(!preg_match($form_items["email"]["regex"], $_POST["your_email"]))
		$errors[] = "your ".$form_items["email"]["error"];

	if(strlen(trim($_POST["message"])) < $msg_min_chars || strlen(trim($_POST["message"])) >  $msg_max_chars )
		$errors[] = $form_items["message"]["error"];

	if(trim($_POST["friend_email2"]) != "")
	{
		if(!preg_match($form_items["email"]["regex"], $_POST["friend_email2"]))
			$errors[] = "Friend 2 ".$form_items["email"]["error"];
	}

	if(trim($_POST["friend_email3"]) != "")
	{
		if(!preg_match($form_items["email"]["regex"], $_POST["friend_email3"]))
			$errors[] = "Friend 3 ".$form_items["email"]["error"];
	}

   return count($errors);
}

function email($from, $from_name, $to, $message)
{
	//header("Location: thankyou.html");return;

	$headers .= "From: ".$from."\r\n";
	$headers .= "Content-type: text/plain; charset=ISO-8859-1";





	$your_domian_name = "shop-orthomolecular.com";
	//edit what you want your vistors to see in their email here
	$subject = $from_name." sent you an invitation to $url";
	$your_message = "Hi!\r\n";
	$your_message.= ucfirst($from_name);
	$your_message.= " wants you to check out $url. This email was forwarded using a tell-a-friend feature. In cases of abuse, contact webmaster@doctorschoice.org\r\n\r\n\r\n\r\n";

	$your_message.= "Sender's Message:\n\r";

	$message=$your_message.stripslashes($message);

	if (mail($to,$subject,$message,$headers) ) {
		return true;
	} else {
		return false;
	}
}

function print_error($errors)
{

	foreach($errors as $error)
	{
		$err.=$error."<br/>";
	}

	echo 
	 "<div style=\"border:1px red solid; font-size:14px; font-weight:normal; color:red; margin:10px; padding:10px;\">
		$err
	 <div>";

}

function form_process()
{	
     

	 $refurl = $_SERVER['HTTP_REFERER']; 
         print $refurl;
	$email=$_POST['email1'];
	$from_name = $_POST["your_name"];
	$from_email = $_POST["your_email"];

	$to = $_POST['email1'].",".$_POST["your_email"].",".$_POST["friend_email2"].",".$_POST["friend_email3"];
	$message = $_POST["message"];

	$error_count = validate_form_items();

	if($error_count == 0)
	{
		if(email($from_email, $from_name, $to, $message))
			header("Location: thankyou.html");
		else
		{
			global $errors;
			$errors[] = "Email couldn't be send at this time. <br>Please report the webmaster of this error.";
		}
	}


}



if(isset($_POST["submit"]))
	form_process();

?>

<script type="text/javascript" src="http://www.plaxo.com/css/m/js/util.js"></script>
<script type="text/javascript" src="http://www.plaxo.com/css/m/js/basic.js"></script>
<script type="text/javascript" src="http://www.plaxo.com/css/m/js/abc_launcher.js"></script>
<script type="text/javascript"><!--
function onABCommComplete() {
  // OPTIONAL: do something here after the new data has been populated in your text area
}
//--></script>



<html>
<title>php-learn-it.com - Email Form Script</title>
<head>
<SCRIPT LANGUAGE="JavaScript">

<!-- Begin
function initMail(form) {
text = "Check out this page: " + window.location;
form.message.value = "Hi " + form.sendto.value + " (" + form.to.value + "):\n\n"
+ text + "\n\nYour Friend,\n" + form.sendername.value + "(" + form.senderemail.value + ")";
return (form.to.value!= "");
}
// End -->
</script>
</head>

<body><center>
<form name=emailform method=post action="http://cgi.freedback.com/mail.pl" target="_new" onSubmit="return initMail(this);">
<input type=hidden name=subject value="** Check Out This Site! **">
<input type=hidden name=message value="">
<table>

</table>
</form>

   <form id="test" method="post" action="<? echo $_POST['self']; ?>">
	<table border="0">
		   

		   <tr>
			   <td colspan="2" style="border-bottom:1px solid black;">

				  <font size="+2"><b>Tell A Friend</b></font>
				  

			   </td>
		   </tr>


			<tr>
			   <td colspan="2">
				   <?php
						global $errors;
						if(count($errors) != 0){
							print_error($errors);
						}
					?>
			   </td>
		   </tr>
		   
		   
		   
		   
		   <tr>
			   <td colspan="2">
					<b>Friend's Email Address(es)</b>*<br/>

					 <input type="text" name="email1" id="name" value="<? echo $_POST['self']; ?>">
  <a href="#" onclick="showPlaxoABChooser('name', 'TellAFriend.html'); return false"><img src="/images/abc/buttons/add_button.gif" alt="Add from my address book"></a><br /><br />
  


			   </td>
			   
		   </tr>

		   <tr>
			   <td>
					<b>Your Name:*</b>
			   </td>
			   <td>
					<b>Your Email:*</b>
			   </td>
		   </tr>

		   <tr>
			   <td>

					<input type="text" name="your_name" id="name" size="20" maxlength="25" value="<?php echo $_POST["your_name"]?>">
			   </td>
			   <td>
					<input type="text" name="your_email" id="email" size="31" maxlength="80" value="<?php echo $_POST["your_email"]?>">
			   </td>
		   </tr>



		   <tr>
			   <td colspan="2">						
					<b>Friend 2 Email Address:</b><br/>
					<input type="text" name="friend_email2" id="name" size="56" maxlength="80" value="<?php echo $_POST["friend_email2"]?>">
			   </td>
	  </tr>

			<tr>
			   <td colspan="2">						
					<b>Friend 3 Email Address:</b><br/>
					<input type="text" name="friend_email3" id="name" size="56" maxlength="80" value="<?php echo $_POST["friend_email3"]?>">
			   </td>
			</tr>

		   <tr>
			   <td>
					<b>Message:*</b> 
			   </td>
			   <td>
					<i>(max 250 characters allowed)</i>
			   </td>
		   </tr>
		   <tr>
			   <td colspan="2">
					<textarea name="message" id="message" cols="42" rows="5"><?php echo $_POST["message"]?></textarea>
			   </td>
		   </tr>
		   <tr>
			   <td colspan="2" align="right">
					<i>(* required fields)</i> <input type="submit" value="submit" name="submit" >



			   </td>
		   </tr>
	</table>
</form>
<form action="<? echo $_POST['self']; ?>" method="post">
</form>
<tr><td> </td>
</tr>

	<!-- Start of StatCounter Code -->
<script type="text/javascript">
var sc_project=4080620; 
var sc_invisible=1; 
var sc_partition=49; 
var sc_click_stat=1; 
var sc_security="95f7c554"; 
</script>

<script type="text/javascript" src="http://www.statcounter.com/counter/counter.js"></script><noscript><div class="statcounter"><a title="web statistics" href="http://www.statcounter.com/free_web_stats.html" target="_blank"><img class="statcounter" src="http://c.statcounter.com/4080620/0/95f7c554/1/" alt="web statistics" ></a></div></noscript>
<!-- End of StatCounter Code -->
</body>

</html>

 

 

Thanks

Try something like this (edit the window settings for your needs):

 

<script type='text/javascript'>

<!--

function popup()

{

window.open("tell_a_friend.php", "_blank", "left=0, top=0, width=400, height=400, scrollbars=no, location=no, menubar=no, status=no, toolbar=no");

}

//-->

</script>

<a href="javascript:popup()"><img src="http://www.shop-orthomolecular.com/store/media/artimages/TellAFriend.gif" alt="Orthomolecular, Tell A Friend" width="174" height="43" border="0" ></a>

 

Then in "tell_a_friend.php", you have the form in which the user inputs information (friend's e-mail address and such) and the PHP code to actually send the mail (remember to validate the user input).

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.