Welcome, Guest. Please login or register.
Did you miss your activation email?
May 27, 2012, 02:40:23 AM

Login with username, password and session length
Search:     Advanced search
Interested in joining the WebsiteBaker team?
For more Information read here or on our new website.
155555 Posts in 21715 Topics by 7737 Members
Latest Member: gx-world
* Home Help Search Login Register
Pages: [1]   Go Down
Print
Author Topic: Send Page to a Friend  (Read 5792 times)
cvfriend

Offline Offline

Posts: 17


« on: June 15, 2007, 06:56:36 AM »

I looked and didn't find a full solution for "send this page to a friend" email function. Here's my try...

Code:
$refpage = getenv("HTTP_REFERER");

if ( $refpage == "http://mysite.com/pages/email-a-friend.php" ) {
echo " "; //trying to refer the email page, so ignore
} else {

echo '<form action="' . $_POST['self'] . '" method="post">';
echo 'Your Name : <input name="from_name" type="text"><br />';
echo 'Your Email : <input name="from_email" type="text"><br /><br />';
echo 'Friend Name : <input name="friend_name" type="text"><br />';
echo 'Friend Email : <input name="friend_email" type="text"><br /><br />';
echo 'Message : <input name="message" type="text"><br /><br />';
echo '<input type="hidden" name="refer" value="' . $refpage . '">';
echo '<input name="Send" type="submit" value="Send">';
echo '</form>';
}

if (@$_POST['Send']=="Send")
{
$from_name=$_POST['from_name'];
$from_email=$_POST['from_email'];
$friend_name=$_POST['friend_name'];
$friend_email=$_POST['friend_email'];
$message=$_POST['message'];
$refer=$_POST['refer'];
$subject = $from_name. " recommends mysite.com";
$send_message= "Hello, \n\n" .$friend_name. " thought you might be interested in viewing this page at mysite.com.";
$send_message = $send_message ." \n\n" . $refer;
$send_message = $send_message . "\n\nFollowing is a note from your friend. \n\n" . $message;
$headers = 'From: ' . $from_email . "\r\n" . 'Reply-To: ' . $from_email . "\r\n" . 'X-Mailer: PHP/' . phpversion();
mail($friend_email, $subject, $send_message, $headers);
echo "<h2>Your email was sent to: " . $friend_email . "</h2>";
}
Logged
spawnferkel

Offline Offline

Posts: 96



« Reply #1 on: June 15, 2007, 11:37:37 AM »

Hi,

nice idea.

could you check the $refpage like this?:

if ( $refpage == $_SERVER['PHP_SELF'] ) {
   echo " "; //trying to refer the email page, so ignore
} else {
...

And what is with the phpmailer class?


Greets

Alexander
Logged
cvfriend

Offline Offline

Posts: 17


« Reply #2 on: June 16, 2007, 09:03:21 AM »

Great suggestion. Thank you.
Logged
bgg

Offline Offline

Posts: 101



« Reply #3 on: July 06, 2007, 06:47:21 AM »

hi there!

have you done this work ?? I need this solution for a site

Babs


I looked and didn't find a full solution for "send this page to a friend" email function. Here's my try...

Code:
$refpage = getenv("HTTP_REFERER");

if ( $refpage == "http://mysite.com/pages/email-a-friend.php" ) {
    echo " "; //trying to refer the email page, so ignore
} else {

echo '<form action="' . $_POST['self'] . '" method="post">';
echo 'Your Name : <input name="from_name" type="text"><br />';
echo 'Your Email : <input name="from_email" type="text"><br /><br />';
echo 'Friend Name : <input name="friend_name" type="text"><br />';
echo 'Friend Email : <input name="friend_email" type="text"><br /><br />';
echo 'Message : <input name="message" type="text"><br /><br />';
echo '<input type="hidden" name="refer" value="' . $refpage . '">';
echo '<input name="Send" type="submit" value="Send">';
echo '</form>';
}

if (@$_POST['Send']=="Send")
{
$from_name=$_POST['from_name'];
$from_email=$_POST['from_email'];
$friend_name=$_POST['friend_name'];
$friend_email=$_POST['friend_email'];
$message=$_POST['message'];
$refer=$_POST['refer'];
$subject = $from_name. " recommends mysite.com";
$send_message= "Hello, \n\n" .$friend_name. " thought you might be interested in viewing this page at mysite.com.";
$send_message = $send_message ." \n\n" . $refer;
$send_message = $send_message . "\n\nFollowing is a note from your friend. \n\n" . $message;
$headers = 'From: ' . $from_email . "\r\n" . 'Reply-To: ' . $from_email . "\r\n" . 'X-Mailer: PHP/' . phpversion();
mail($friend_email, $subject, $send_message, $headers);
echo "<h2>Your email was sent to: " . $friend_email . "</h2>";
}
Logged
AzAkers

Offline Offline

Posts: 40


WWW
« Reply #4 on: July 16, 2007, 08:34:26 PM »

Just implemented this - works fantastic!

great port over on a nice piece of functionality - I'm no programmer but I've been working with trying to do that for a while Cheesy

Thanks!
Logged

Contributor?  THANKS!!

WB Sites:
AZ Ladies Ministries
Logo Design in progress
hudge

Offline Offline

Posts: 174


WWW
« Reply #5 on: July 16, 2007, 09:58:03 PM »

Here is what I use by creating a code page:

Code:
<?php

if(isset($_GET['url'])){
    
$urlToSend $_GET['url'];
}


$form_block "
<table width=\"500\"><tr><td>
<h1>Email this page</h1>
<form action=\"
$formToSend\" method=\"post\" name=\"emailForm\">
    <input name=\"url\" type=\"hidden\" value=\"
$urlToSend\" />
    <table width=\"98%\" border=\"0\" cellspacing=\"1\" cellpadding=\"0\" id=\"mailer\">
      <tr>
        <td width=\"100\">Friends Name:</td>
        <td><input name=\"friendName\" type=\"text\" value=\"\" size=\"\" style=\"width:100%;\" /></td>
      </tr>
      <tr>
        <td>Friends Email:</td>        <td><input name=\"friendEmail\" type=\"text\" value=\"\" size=\"\" style=\"width:100%;\"  /></td>
      </tr>
      <tr>
        <td>Your Name:</td>
        <td><input name=\"yourName\" type=\"text\" value=\"\" size=\"\" style=\"width:100%;\" /></td>
      </tr>
      <tr>
        <td>Your Email:</td>
        <td><input name=\"yourEmail\" type=\"text\" value=\"\" size=\"\" style=\"width:100%;\" /></td>
      </tr>
      <tr>
        <td>Message:</td>
        <td><textarea name=\"message\" cols=\"\" rows=\"5\" style=\"width:100%;\" ></textarea></td>
      </tr>
      <tr>
        <td>Page Link:</td>
        <td><input name=\"includedText\" type=\"text\" style=\"width:100%; border: none;  \" readonly=\"true\" value=\"
$urlToSend\" />
        </td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td><input name=\"submit\" type=\"submit\" value=\"Send This Form\"/>&nbsp;<input name=\"cancel\" type=\"button\" value=\"Cancel\" onclick=\"javascript: window.location='
$urlToSend'; \"/></td>
      </tr>
    </table>
<br />
<p style=\"font-size: 10px; color:#999999; \">* All fields required to send page.</p>
</form>
</td></tr></table>
"
;


if (!isset(
$_POST['url'])) {

    
// they need to see the form
    
echo "$form_block";
    
} else if (isset(
$_POST['url'])) {

$url $_POST['url'];
$friendName $_POST['friendName'];
$friendEmail $_POST['friendEmail'];
$yourName $_POST['yourName'];
$yourEmail $_POST['yourEmail'];
$message $_POST['message'];
$includedText $_POST['includedText'];

    if (
$friendName == "") {
        
$fname_err "<font color=red>Please enter your friends name!</font><br>";
        
$send "no";
    } 
    
    if (
$friendEmail == "") {
        
$femail_err "<font color=red>Please enter your friends e-mail address!</font><br>";
        
$send "no";
    } 

    if (
$yourName == "") {
        
$yname_err "<font color=red>Please enter your name!</font><br>";
        
$send "no";
    } 
    
    if (
$yourEmail == "") {
        
$yemail_err "<font color=red>Please enter your e-mail address!</font><br>";
        
$send "no";
    } 
    
    if (
$message == "") {
        
$message_err "<font color=red>Please enter a message!</font><br>";
        
$send "no";
    } 
    
    if (
$send != "no") {
    
        
// it's ok to send!

        
$msg "$message\n\n";
        
$msg .= "$yourName <$yourEmail> thinks you might want to check this out.\n";
        
$msg .= "$includedText\n\n";
    
        
$to $friendEmail;
        
$subject "Check out this page";
        
$mailheaders "From: website <noreply@domain.com> \n";
        
$mailheaders .= "Reply-To: noreply@domain.com\n\n";

        
mail($to$subject$msg$mailheaders);
        echo 
"<P>Mail has been sent!</p>";
        
    } else if (
$send == "no") {
    
        echo 
"$fname_err";
        echo 
"$femail_err";
        echo 
"$yname_err";
        echo 
"$yemail_err";
        echo 
"$message_err";
        echo 
"$form_block";  
            
    } 
}
?>


Logged

: Member of the Baker's Dozen :
Baking at 350˚ for 2 hours now...
hudge

Offline Offline

Posts: 174


WWW
« Reply #6 on: July 16, 2007, 10:19:29 PM »

If you add this to the top of mine:

// Include config file
require(../config.php');

then you can update

$mailheaders = "From: ".WEBSITE_TITLE." <".SERVER_EMAIL."> \n";
$mailheaders .= "Reply-To: ".SERVER_EMAIL."\n\n";

to use the server email.
Logged

: Member of the Baker's Dozen :
Baking at 350˚ for 2 hours now...
nickdiel

Offline Offline

Posts: 4


« Reply #7 on: June 04, 2008, 01:06:51 PM »

does anyone have this in a downloadable module?

I could use a module like this!

Thanks,
Nick
Logged
marathoner

Offline Offline

Posts: 495


« Reply #8 on: June 04, 2008, 02:46:46 PM »

Why don't you simply use the code snippet above?
Logged
nickdiel

Offline Offline

Posts: 4


« Reply #9 on: June 04, 2008, 03:23:26 PM »

I dont know how... I'm a n00b....

I have tried to read the manual to install it but it is in German, and I dont really understand German:S

Can anyone tell me how, in plain english or dutch?

Regards,

Nick
Logged
Luckyluke

Offline Offline

Posts: 555



« Reply #10 on: June 04, 2008, 05:07:22 PM »

Hoi,

The manual exist also in Dutch (http://help.websitebaker.org/pages/nl/welkom.php).
And now in Dutch:

Hoi,
Maak in je pagina een codesectie (rechtsbovenaan zie je "Beheer secties"). Gebruik nu "toevoegen sectie" en selecteer "Code".
Wijzig de pagina en plak de code van Hudge in dit code veld. Vergeet niet te bewaren.

Groetjes,
Luc
Logged
Bramus
Forum Team
*****
Offline Offline

Posts: 601


WWW
« Reply #11 on: June 04, 2008, 09:21:08 PM »

i thought if you were using the code section you dont need to use <?php again to open up in the code section. So if it is not working remove the <?php tag in the beginning and the ?> at the end of the code
Logged

BRAMUS Internet Services
Luckyluke

Offline Offline

Posts: 555



« Reply #12 on: June 05, 2008, 12:14:24 PM »

i thought if you were using the code section you dont need to use <?php again to open up in the code section. So if it is not working remove the <?php tag in the beginning and the ?> at the end of the code
I use WB 2.7 and after I save the code including <?php and ?>, these were gone. So, you can use them.

But I test succesfully the snipped from Hudge. However, the link wasn't filled in. But when I add the extra require(../config.php'); as told on the next post, it doesn't work anymore. Strange...
Logged
nickdiel

Offline Offline

Posts: 4


« Reply #13 on: June 05, 2008, 12:49:27 PM »

I had the same problem with the URL so I just re-wrote an alternative for the url-message:
Code:
<?
  $url = "http://" . $domain . $_SERVER['REQUEST_URI'];
  echo "The alternative way: " . $url;
?>
So a full link is shown like: http://www.yourwebsitebakerdomain.com/test/test-link.php

It might be helpfull.

I have another question though... I have now implemented te code in my index.php but is there someway I could only show this at certain pages? So.. wouldn't it be good if this was a module instead of a code snippet?

Kind regards,
Nick
Logged
weiry

Offline Offline

Posts: 92


« Reply #14 on: January 07, 2009, 04:43:09 AM »

Hi All,

I used the original code from cvfriend and then included the suggested change from spawnferkel and created a hidden code page inside my website. I also added some code so that the browser could see what page they were referring, as well as a heading for the page.

I then created a div id inside the index.php file above the footer and loaded an image and some text and then linked the new div id to the hidden page. This allowed me to style the text with CSS for the new div id.

This works well, on every page at the bottom, just above the footer. I thought I would post back the amended code for anyone who may be interested.

Cheers. smiley

Code:
$refpage = getenv("HTTP_REFERER");

if ( $refpage == $_SERVER['PHP_SELF'] ) {
   echo " "; //trying to refer the email page, so ignore
} else {

echo '<h2>Referral details</h2>';
echo '<form action="' . $_POST['self'] . '" method="post">';
echo 'Your Name : <input name="from_name" type="text"><br />';
echo 'Your Email : <input name="from_email" type="email"><br /><br />';
echo 'Friend Name : <input name="friend_name" type="text"><br />';
echo 'Friend Email : <input name="friend_email" type="email"><br /><br />';
echo 'Message : <input name="message" type="text"><br /><br />';
echo 'Referred Page : '.$refpage.'<br /><br />';
echo '<input type="hidden" name="refer" value="' . $refpage . '">';
echo '<input name="Send" type="submit" value="Send">';
echo '</form>';
}

if (@$_POST['Send']=="Send")
{
$from_name=$_POST['from_name'];
$from_email=$_POST['from_email'];
$friend_name=$_POST['friend_name'];
$friend_email=$_POST['friend_email'];
$message=$_POST['message'];
$refer=$_POST['refer'];
$subject = $from_name. " recommends yourdomain.com";
$send_message= "Hello, \n\n" .$friend_name. " thought you might be interested in viewing this page at www.yourdomain.com";
$send_message = $send_message ." \n\n" . $refer;
$send_message = $send_message . "\n\nFollowing is a message from your friend. \n\n" . $message;
$headers = 'From: ' . $from_email . "\r\n" . 'Reply-To: ' . $from_email . "\r\n" . 'X-Mailer: PHP/' . phpversion();
mail($friend_email, $subject, $send_message, $headers);
echo "<h2>Your email has been sent to: " . $friend_email . "</h2>";
}
Logged
mviens

Offline Offline

Posts: 57


« Reply #15 on: February 03, 2009, 02:42:25 AM »

Nice piece of code and just what I was looking for!

I have some limited php experience and was wondering how I would modify the form so that after clicking "Send", the page would reload without the form and display a basic thank you message:
"Your email has been sent. Click here to return to your previous location."

"here" would link back to the initial referring page.

Thanks as always.

Michael
Logged
Hans

Offline Offline

Posts: 565


« Reply #16 on: June 01, 2009, 11:41:51 PM »

Hi all
I made some changes to the code to make it look better (in my opinion).
Feel free to change my poor English wink
Thanks weiry for your code! Hope you agree about the look.
Hans
Code:
$refpage = getenv("HTTP_REFERER");

if ( $refpage == $_SERVER['PHP_SELF'] ) {
   echo " "; //trying to refer the email page, so ignore
} else {

echo '<h2>Tip your friend about this page</h2>';
echo '<form action="' . $_POST['self'] . '" method="post">';
echo '<table width="90%">';
echo '<tr>';
echo '<td>';
echo 'Your forname <b>and</b> surname:><input name="from_name" type="text" size="40">';
echo '</td>';
echo '<td>';
echo '<b>Your E-mail address:</b><input name="from_email" type="email" size="40">';
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td>';
echo '<b>Only the forname</b> of your friend:<input name="friend_name" type="text" size="40">';
echo '</td>';
echo '<td>';
echo '<b>Your friend\'s e-mail address:</b><input name="friend_email" type="email" size="40">';
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td colspan="2">';
echo '<b>Comment or explanation:<br></b><textarea input name="message" type="text" COLS="65" ROWS="4">Here you can enter some text to explain your tip.</textarea>';
echo '</td>';
echo '</tr>';
echo '</table>';
echo 'Page reference : '.$refpage.'<br /><br />';
echo '<input type="hidden" name="refer" value="' . $refpage . '">';
echo '<input name="Send" type="submit" value="Send">';

echo '</form>';
}

if (@$_POST['Send']=="Send")
{
$from_name=$_POST['from_name'];
$from_email=$_POST['from_email'];
$friend_name=$_POST['friend_name'];
$friend_email=$_POST['friend_email'];
$message=$_POST['message'];
$refer=$_POST['refer'];
$subject = $from_name. " recommends you a good website.";
$send_message= "Hello " .$friend_name.", I think you might be interested in the following link:\nGreets,\n" .$from_name;
$send_message = $send_message ." \n\n" . $refer;
$send_message = $send_message . "\n\nFurther comment: \n\n" . $message;
$headers = 'From: ' . $from_email . "\r\n" . 'Reply-To: ' . $from_email . "\r\n" . 'X-Mailer: PHP/' . phpversion();
mail($friend_email, $subject, $send_message, $headers);
echo "<h2>Your tip has been sent to: " . $friend_email . "</h2>";
}
« Last Edit: June 01, 2009, 11:46:30 PM by Hans » Logged

Hans - Nijmegen - The Netherlands
Vincent

Offline Offline

Posts: 360


WWW
« Reply #17 on: March 25, 2010, 10:37:25 AM »

HI, I used this snippet, but found a typo in the last code, so it diddn't work.
Here's the correct code:

Code:
$refpage = getenv("HTTP_REFERER");

if ( $refpage == $_SERVER['PHP_SELF'] ) {
   echo " "; //trying to refer the email page, so ignore
} else {

echo '<h2>Tip your friend about this page</h2>';
echo '<form action="' . $_POST['self'] . '" method="post">';
echo '<table width="90%">';
echo '<tr>';
echo '<td>';
echo 'Your forname <b>and</b> surname:<input name="from_name" type="text" size="40">';
echo '</td>';
echo '<td>';
echo '<b>Your E-mail address:</b><input name="from_email" type="email" size="40">';
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td>';
echo '<b>Only the forname</b> of your friend:<input name="friend_name" type="text" size="40">';
echo '</td>';
echo '<td>';
echo '<b>Your friend\'s e-mail address:</b><input name="friend_email" type="email" size="40">';
echo '</td>';
echo '</tr>';
echo '<tr>';
echo '<td colspan="2">';
echo '<b>Comment or explanation:<br></b><textarea input name="message" type="text" COLS="65" ROWS="4">Here you can enter some text to explain your tip.</textarea>';
echo '</td>';
echo '</tr>';
echo '</table>';
echo 'Page reference : '.$refpage.'<br /><br />';
echo '<input type="hidden" name="refer" value="' . $refpage . '">';
echo '<input name="Send" type="submit" value="Send">';

echo '</form>';
}

if (@$_POST['Send']=="Send")
{
$from_name=$_POST['from_name'];
$from_email=$_POST['from_email'];
$friend_name=$_POST['friend_name'];
$friend_email=$_POST['friend_email'];
$message=$_POST['message'];
$refer=$_POST['refer'];
$subject = $from_name. " recommends you a good website.";
$send_message= "Hello " .$friend_name.", I think you might be interested in the following link:\nGreets,\n" .$from_name;
$send_message = $send_message ." \n\n" . $refer;
$send_message = $send_message . "\n\nFurther comment: \n\n" . $message;
$headers = 'From: ' . $from_email . "\r\n" . 'Reply-To: ' . $from_email . "\r\n" . 'X-Mailer: PHP/' . phpversion();
mail($friend_email, $subject, $send_message, $headers);
echo "<h2>Your tip has been sent to: " . $friend_email . "</h2>";}
Logged
Pages: [1]   Go Up
Print
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!