Send Page to a Friend

Vincent

HI, I used this snippet, but found a typo in the last code, so it diddn't work.
Here's the correct 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>";}

Hans

#17
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
$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>";
}
Hans - Nijmegen - The Netherlands

mviens

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

weiry

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. :-)

$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>";
}

nickdiel

I had the same problem with the URL so I just re-wrote an alternative for the url-message:

<?
  $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

Luckyluke

Quote from: 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
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...

Bramus

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
BRAMUS Internet Services

Luckyluke

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

nickdiel

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

marathoner

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

nickdiel

does anyone have this in a downloadable module?

I could use a module like this!

Thanks,
Nick

hudge

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.
: Member of the Baker's Dozen :
Baking at 350˚ for 2 hours now...

hudge

Here is what I use by creating a code page:


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


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

AzAkers

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!

bgg

hi there!

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

Babs


Quote from: 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...


$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>";
}


cvfriend

Great suggestion. Thank you.

spawnferkel

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

cvfriend

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


$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>";
}