WebsiteBaker Community Forum

WebsiteBaker Support (2.8.x) => Droplets & Snippets => Topic started by: cvfriend on June 15, 2007, 07:56:36 AM

Title: Send Page to a Friend
Post by: cvfriend on June 15, 2007, 07: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: [Select]
$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>";
}
Title: Re: Send Page to a Friend
Post by: spawnferkel on June 15, 2007, 12:37:37 PM
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
Title: Re: Send Page to a Friend
Post by: cvfriend on June 16, 2007, 10:03:21 AM
Great suggestion. Thank you.
Title: Re: Send Page to a Friend
Post by: bgg on July 06, 2007, 07: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: [Select]
$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>";
}
Title: Re: Send Page to a Friend
Post by: AzAkers on July 16, 2007, 09: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 :D

Thanks!
Title: Re: Send Page to a Friend
Post by: hudge on July 16, 2007, 10:58:03 PM
Here is what I use by creating a code page:

Code: [Select]
<?php

if(isset($_GET[&#39;url&#39;])){
    
$urlToSend $_GET[&#39;url&#39;];
}


$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=&#39;
$urlToSend&#39;; \"/></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[&#39;url&#39;])) {

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

$url $_POST[&#39;url&#39;];
$friendName $_POST[&#39;friendName&#39;];
$friendEmail $_POST[&#39;friendEmail&#39;];
$yourName $_POST[&#39;yourName&#39;];
$yourEmail $_POST[&#39;yourEmail&#39;];
$message $_POST[&#39;message&#39;];
$includedText $_POST[&#39;includedText&#39;];

    
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&#39;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";  
            
    } 
}
?>


Title: Re: Send Page to a Friend
Post by: hudge on July 16, 2007, 11: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.
Title: Re: Send Page to a Friend
Post by: nickdiel on June 04, 2008, 02:06:51 PM
does anyone have this in a downloadable module?

I could use a module like this!

Thanks,
Nick
Title: Re: Send Page to a Friend
Post by: marathoner on June 04, 2008, 03:46:46 PM
Why don't you simply use the code snippet above?
Title: Re: Send Page to a Friend
Post by: nickdiel on June 04, 2008, 04: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
Title: Re: Send Page to a Friend
Post by: Luckyluke on June 04, 2008, 06:07:22 PM
Hoi,

The manual exist also in Dutch (http://help.WebsiteBaker.org/pages/nl/welkom.php (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
Title: Re: Send Page to a Friend
Post by: Bramus on June 04, 2008, 10: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
Title: Re: Send Page to a Friend
Post by: Luckyluke on June 05, 2008, 01: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...
Title: Re: Send Page to a Friend
Post by: nickdiel on June 05, 2008, 01:49:27 PM
I had the same problem with the URL so I just re-wrote an alternative for the url-message:
Code: [Select]
<?
  $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
Title: Re: Send Page to a Friend
Post by: weiry 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. :-)

Code: [Select]
$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>";
}
Title: Re: Send Page to a Friend
Post by: mviens 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
Title: Re: Send Page to a Friend
Post by: Hans on June 02, 2009, 12:41:51 AM
Hi all
I made some changes to the code to make it look better (in my opinion).
Feel free to change my poor English ;-)
Thanks weiry for your code! Hope you agree about the look.
Hans
Code: [Select]
$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>";
}
Title: Re: Send Page to a Friend
Post by: Vincent 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: [Select]
$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>";}