NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming > CODE
Reload this Page Simple PHP Tell-A-Friend

CODE This forum is for posting code snippets and example scripts that aren't quite tutorials, but could be useful for others. You may post code snippets and/or completed scripts that you've written and want to share here.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 10-31-2005, 09:41 AM THREAD STARTER               #1 (permalink)
Senior Member
 
Eric's Avatar
Join Date: Mar 2005
Posts: 4,948
Eric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatness
 

Member of the Month
MOTM September 2005
Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Animal Rescue Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Baby Health Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse Diabetes Protect Our Planet Multiple Sclerosis Autism Adoption Special Olympics

Simple PHP Tell-A-Friend


Had some time on my hands, so, wrote this little script. Rather simple, and should be relatively straightforward... All you need to do is save as tellafriend.php, functions.php and upload. Then link to it, like so:
PHP Code:
<a href="./tellafriend.php?ref=<?php echo $_SERVER['SCRIPT_NAME']; ?>">Tell a friend</a>
EDIT: Updated to v1.0.1 on June 7, 2006
For some reason, using HTTP_REFERER wouldn't work :s No idea atm, but the above ^^ is a little work-around

tellafriend.php
PHP Code:
<?php

/****************************************************************************
*
*   Author   : Eric Sizemore ( www.secondversion.com )
*   Package  : SV's Tell-a-friend
*   Version  : 1.0.1
*   Copyright: (C) 2005-2006 Eric Sizemore
*   Site     : www.secondversion.com
*   Email    : esizemore05@gmail.com
*   File     : tellafriend.php
*
*   This program is free software; you can redistribute it and/or modify
*   it under the terms of the GNU General Public License as published by
*   the Free Software Foundation; either version 2 of the License, or
*   (at your option) any later version.
*
*   This program is distributed in the hope that it will be useful,
*   but WITHOUT ANY WARRANTY; without even the implied warranty of
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
*   GNU General Public License for more details.
*
****************************************************************************/

// ####################### Define Important Constants #######################
// You'll need to change SITE_NAME, SUBJECT and optionally MSG_WORD_WRAP
define('IN_TAF'true);
define('SITE_NAME''YourSite.com');
define('SUBJECT''Hello friend! Thought you might be interested in ' SITE_NAME);
define('MSG_WORD_WRAP'75);

// ############################### Functions ################################
require_once('functions.php');

$ref = (!empty($_GET['ref'])) ? clean(sanitize($_GET['ref'], 'default')) : '';

// ################################## HTML ##################################
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Tell-A-Friend</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
</head>

<body>

<p align="center"><b>Please tell your friends about us.</b></p>
<table cellpadding="2" cellspacing="0" style="border-collapse: collapse; border: 1px solid #111111;">
<form method="post" action="tellafriend.php?ref=<?php echo $ref?>" style="display: inline;">
<tr>
  <td>Your Name:</td>
  <td><input type="text" name="name" size="20"></td>
</tr>
<tr>
  <td>Your Email address:</td>
  <td><input type ="text" name="email" size="20"></td>
</tr>
<tr>
  <td>Friend Email address:</td>
  <td><input type ="text" name="femail" size="20"></td>
</tr>
<tr>
  <td valign="top">Message:</td>
  <td><textarea name="message" rows="5" cols="20"></textarea></td>
</tr>
<tr>
  <td></td>
  <td><input type="submit" name="submit" value="Submit"></td>
</tr>
</form>
</table>
<?php

// ############################ Main Script Start ###########################
if (isset($_POST['submit']) AND $_POST['submit'] != '')
{
    
$name    clean(sanitize($_POST['name'], 'default'));
    
$email   clean(sanitize($_POST['email'], 'default'));
    
$femail  clean(sanitize($_POST['femail'], 'default'));
    
$message clean(wordwrap(sanitize($_POST['message'], 'light'), MSG_WORD_WRAP));
    
$message str_replace("\n"'<br>'$message);

    if (!
is_valid_email($email) OR is_email_injection($email) OR !is_valid_email($femail) OR is_email_injection($femail))
    {
        echo 
'<br />Your email (or your friends) is either invalid or left blank. Please try again.';
    }
    else
    {
        
$e $email;

        if (empty(
$name) OR empty($message) OR is_email_injection($name))
        {
            echo 
'<br />One or more required fields left blank. Please try again.';
        }
        else
        {
            
$headers 'MIME-Version: 1.0' "\r\n";
            
$headers .= 'Content-type: text/html; charset=iso-8859-1' "\r\n";
            
$headers .= 'Content-Transfer-Encoding: 8bit' "\r\n";
            
$headers .= 'From: ' $name ' <' $e '>' "\r\n";
            
$headers .= 'X-Priority: 1' "\r\n";
            
$headers .= 'X-Mailer: SVs Tell-a-friend v1.0.1' "\r\n";

            
$send mail($femailSUBJECT"
            <html>
            <head>
            <title>Email from 
$name</title>
            </head>
????: NamePros.com http://www.namepros.com/code/136478-simple-php-tell-a-friend.html

            <body>

            <p>Hello! 
$name is sending you this message because they think you'll enjoy our website: " SITE_NAME ". <br>Their message is included below.</p>
            
            <p>
$message. ((!empty($ref)) ? '<br><br><a href="http://' $_SERVER['HTTP_HOST'] . $ref '">' SITE_NAME '</a>' '') . "</p>

            </body>
            </html>"
$headers);

            if (
$send)
            {
                echo 
'<br />Thank you, ' $name ', for telling your friend about us.';
            }
            else
            {
                echo 
'<br />Seems to have been a problem sending the email. Please try again.';
            }
        }
    }
}

// That's all folks!
?>
<p>Powered by <a href="http://www.secondversion.com">SVs Tell-a-friend v1.0.1</a></p>

</body>
</html>
functions.php
PHP Code:
<?php

/****************************************************************************
*
*   Author   : Eric Sizemore ( www.secondversion.com )
*   Package  : SV's Tell-a-friend
*   Version  : 1.0.1
*   Copyright: (C) 2005-2006 Eric Sizemore
*   Site     : www.secondversion.com
*   Email    : esizemore05@gmail.com
*   File     : functions.php
*
*   This program is free software; you can redistribute it and/or modify
*   it under the terms of the GNU General Public License as published by
*   the Free Software Foundation; either version 2 of the License, or
*   (at your option) any later version.
*
*   This program is distributed in the hope that it will be useful,
*   but WITHOUT ANY WARRANTY; without even the implied warranty of
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
*   GNU General Public License for more details.
*
****************************************************************************/

if (!defined('IN_TAF'))
{
    die();
}

/*
Strip any unsafe tags/chars/attributes from input data

@param  string  Data to be cleaned
@param  string  Level or 'strength' of cleaning - default or light
                pretty much the same, but one will remove new lines, and CRLF
@return string
*/
function sanitize($data$strength)
{
    switch (
$strength)
    {
        case 
'':
        case 
'default':
             
$search = array('@<script[^>]*?>.*?</script>@si',
                 
'@<applet[^>]*?>.*?</applet>@si',
                 
'@<object[^>]*?>.*?</object>@si',
                 
'@<iframe[^>]*?>.*?</iframe>@si',
                 
'@<style[^>]*?>.*?</style>@si',
                 
'@<form[^>]*?>.*?</form>@si',
                 
'@<[\/\!]*?[^<>]*?>@si',
                 
'@([\r\n])[\s]+@',
                 
'@&(lt|#60);@i',
                 
'@&(gt|#62);@i'
             
);
             break;
        case 
'light':
             
$search = array('@<script[^>]*?>.*?</script>@si',
                 
'@<applet[^>]*?>.*?</applet>@si',
                 
'@<object[^>]*?>.*?</object>@si',
                 
'@<iframe[^>]*?>.*?</iframe>@si',
                 
'@<style[^>]*?>.*?</style>@si',
                 
'@<form[^>]*?>.*?</form>@si',
                 
'@<[\/\!]*?[^<>]*?>@si',
                 
'@&(amp|#38);@i',
                 
'@&(lt|#60);@i',
                 
'@&(gt|#62);@i'
             
);
             break;
    }

    return 
preg_replace($search''strip_tags($data));
????: NamePros.com http://www.namepros.com/showthread.php?t=136478
}

/*
Trim and strip slashes from data

@param  string  Data to be cleaned
@return string
*/
function clean($data)
{
    return 
trim(stripslashes($data));
}

/*
Tests for a valid email address

@param  string  Email address
@return boolean
*/
function is_valid_email($email)
{
    
$pattern '/^[a-z0-9&\.\-_\+]+@[a-z0-9\-]+\.([a-z0-9\-]+\.)*?[a-z]{2,6}+$/is';
    
    return (
preg_match($pattern$email)) ? true false;
}

/*
Tests input data from the contact form for email injection - very basic

@param  string  Data to check
@return boolean
*/
function is_email_injection($data)
{
    return (
eregi("(To:|Bcc:|Cc:|Content-type:|\\r\\n)"urldecode($data))) ? true false;
}

?>
-Eric
Last edited by SecondVersion; 06-07-2006 at 04:23 AM.
Eric is offline  
Old 11-01-2005, 09:06 AM   #2 (permalink)
Senior Member
 
Muneeb2Good's Avatar
Join Date: Jun 2005
Location: Planet Mars
Posts: 1,400
Muneeb2Good is a name known to allMuneeb2Good is a name known to allMuneeb2Good is a name known to allMuneeb2Good is a name known to allMuneeb2Good is a name known to allMuneeb2Good is a name known to allMuneeb2Good is a name known to allMuneeb2Good is a name known to all
 




Wowwww its really Superb i have done it and its working ...Thanks

well i have a Question that is it working for all the browsers or only for IE 5.5 or higher ....Well thanks again !
Muneeb2Good is offline  
Old 11-01-2005, 04:58 PM THREAD STARTER               #3 (permalink)
Senior Member
 
Eric's Avatar
Join Date: Mar 2005
Posts: 4,948
Eric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatness
 

Member of the Month
MOTM September 2005
Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Animal Rescue Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Baby Health Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse Diabetes Protect Our Planet Multiple Sclerosis Autism Adoption Special Olympics
Thanks Yes It will work in all browsers
Eric is offline  
Old 05-02-2006, 09:36 AM   #4 (permalink)
Account Closed
Join Date: Jan 2006
Posts: 459
wvccboy is a jewel in the roughwvccboy is a jewel in the roughwvccboy is a jewel in the rough
 



Looks nice!
wvccboy is offline  
Old 05-02-2006, 09:26 PM   #5 (permalink)
NamePros Regular
 
nick's Avatar
Join Date: Jun 2004
Location: Iowa City
Posts: 705
nick has much to be proud ofnick has much to be proud ofnick has much to be proud ofnick has much to be proud ofnick has much to be proud ofnick has much to be proud ofnick has much to be proud ofnick has much to be proud of
 


Save The Children
Originally Posted by wvccboy
Looks nice!
yes it does, i use it on my sites
__________________
formally ninedogger
------
Want to talk to a stranger? -->| Click Here | TalkToAStranger.com | <-- Meet New Friends
nick is offline  
Old 05-02-2006, 09:59 PM   #6 (permalink)
NamePros Member
Join Date: Apr 2006
Posts: 102
YaSHaRz is an unknown quantity at this point
 



Thanks for the script, hopefuly I can get it working fine.
By the way, the demo link is down.
YaSHaRz is offline  
Old 06-07-2006, 04:26 AM THREAD STARTER               #7 (permalink)
Senior Member
 
Eric's Avatar
Join Date: Mar 2005
Posts: 4,948
Eric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatness
 

Member of the Month
MOTM September 2005
Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Animal Rescue Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Baby Health Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse Diabetes Protect Our Planet Multiple Sclerosis Autism Adoption Special Olympics
Updated to 1.0.1, see first post.

-Eric
Eric is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Randomingly choosing a quote from Database, PHP SquireQuack Programming 9 10-31-2005 06:50 AM
Simple PHP Form Issue buddybuddha Programming 3 10-30-2005 03:53 PM
Simple gz compression GeorgeB CODE 3 07-01-2005 11:56 AM

Liquid Web Smart Servers  
All times are GMT -7. The time now is 01:02 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger