Location: PHPKode > scripts > Create Your Own Directory > cms/functions/refer.php
  <html>
  <?php
  
  include "../header.php";
  ?>
  <SCRIPT LANGUAGE="JavaScript">
  function textCounter(add,lenf) {
	var cadd = add;
	var cle = cadd.value.length;
	var maxl = 125;

	if(cle > maxl){
		cadd.value = cadd.value.substring(0, maxl);
		lenf.value = 0;
	}else{
		var ll = maxl-cle;
		lenf.value= ll;
	}
  }
  </script>
  <?php
  $ref=$_SERVER[HTTP_REFERER];
  //echo"$ref";
  $domain = strstr($ref,$userdomain);
  $block="true";
  $cntid=$_GET['cntid'];
  $fmaile=$_POST['fmaile'];
  $usrname=$_POST['usrname'];
  $usrmail=$_POST['usrmail'];
  $pmessage=$_POST['pmessage'];
  $fname1=$_POST['fname1'];
  $fname2=$_POST['fname2'];
  $fname3=$_POST['fname3'];
  $fname4=$_POST['fname4'];
  $fmail=array();
  for($i=1;$i<=4;$i++)
  {
    $temp=$_POST['fmail'.$i];
    if($temp !="")
    {
	array_push($fmail, $temp);
    }
  }
  $cnt=sizeof($fmail);
  $duplicate="";

  if (count(array_unique($fmail)) < count($fmail))
  {
	$duplicate="true";
  }

  include "class.phpmailer.php";
  $mail = new PHPMailer();
  $mail->From     = "$usrmail";
  $mail->FromName = "$usrname";
  $mail->IsMail();
 
  if($fmaile=="yes")
  {
   for($k=1;$k<=$cnt;$k++)
   {
     if($domain && ($usrmail !=$fmail[$k])  )
     {
	$umail="$fmail[$k]";
	if($umail !="")
	{ 


        if($usrmail !=" " && $fmail[1]!=" ")
	  {
	    
          $mail->Subject = "invitation from $usrname";
          $message1 ="Your friend has invited you to view this resource and your friend has added following message to you<br><br>";
	    $message=$message1;
	    $mail->Body    = $message.$pmessage;
          $mail->ClearAddresses();
	    $mail->AddAddress("$umail", "");
	    if($duplicate !="true")
	    {
	      if(!($mail->Send()))
	      {
  	        echo "<div align=center style=\"color:red;\">There has been a mail error sending to " . $umail . "<br> </div>";
	        // Clear all addresses for next loop
	      }else{
		  $block="false";
	      }
	    }else{
		echo"<div align=center style=\"color:red;\">your mail has not send to your friend<br></div>";
	    }
         
	  }else
	  {
         echo"Enter atleast one email in the mandatory field along with your mailid";
	  }		
      }
   }
   }			
  }
  $query="select * from cnt where cntid=$cntid";
  $result=mysql_query($query);
  while($row=mysql_fetch_array($result,MYSQL_ASSOC))
  {
    $contents=$row['contents'];
    

  }
$arr=split('####',$contents);
$title=$arr[0];
  ?>
  <?php
  if($block=="true")
  {
    echo"<form method=post action=\"\">
    <div align=center><font style=\" font-size:18px;\"><br>Refer <font style=\"color:green; font-size:18px;\">$title</font>  to your Friend </font></div>
    <br>
    <table align=center height=100% width=70%  cellpadding=0 cellspacing=0  style=\"border: 1px solid #186310;\">
      <tr><td align=center height=20 colspan=3></td></tr>
      <tr><td width=20%><div style=\"margin-left: 20px;\"><strong>Resource Title:</strong></div></td><td colspan=2><input type=text name=srcname value=\"$title\" maxlength=100 size=50 readonly></input></td></tr>
       <tr><td align=center width=24%></td><td align=center><strong>Your name</strong></td><td align=center colspan=2><strong>Your Mailid</strong></input></td></tr>
      <tr><td align=right width=24%></td><td align=center><input type=text name=usrname maxlength=50></input></td><td align=center colspan=2><input type=text name=usrmail maxlength=50></input></td></tr>
      <tr><td align=right width=24%></td><td width=10 align=center><strong>Friend's Name</strong></td><td align=center><strong>Friend's Mailid</strong></input></td></tr>
      <tr><td align=right width=24% height=30><strong>Friend1*</strong></td><td align=center><input type=text name=fname1 maxlength=50></input></td><td align=center><input type=text name=fmail1 maxlength=50></input></td></tr>
      <tr><td align=right width=24% height=30><strong>Friend2*</strong></td><td align=center><input type=text name=fname2 maxlength=50></input></td><td align=center><input type=text name=fmail2 maxlength=50></input></td></tr>
      <tr><td align=right width=24% height=30><strong>Friend3</strong></td><td align=center><input type=text name=fname3 maxlength=50></input></td><td align=center><input type=text name=fmail3 maxlength=50></input></td></tr>
      <tr><td align=right width=24% height=30><strong>Friend4</strong></td><td align=center><input type=text name=fname4 maxlength=50></input></td><td align=center><input type=text name=fmail4 maxlength=50></input></td></tr> 
      <tr><td align=center colspan=3 class=heading>Enter your Message</td></tr>
      <tr><td colspan=3 align=center ><textarea rows=6 cols=40  name=pmessage onKeyUp=textCounter(this,this.form.remLen)></textarea>
      <input readonly type=text name=remLen size=3 maxlength=3 value=125></td></tr>
      <tr><td colspan=3 align=center><input type=hidden name=fmaile value=\"yes\">
      <input type=submit name=sub value=send></td></tr>
    </table>
    </form>";
  }else
  {
    echo" <div align=center>Your Invitation has been send to your friends <br>
    <a href=$home"."functions/refer.php?cntid=$cntid&sub=yes>BACK</a></div>";
  }
  ?>
  <?php
    include '../footer.php';
  ?>
Return current item: Create Your Own Directory