Computing.Net > Forums > Web Development > Form to email page link...

Form to email page link...

Reply to Message Icon

Original Message
Name: jinx
Date: March 12, 2007 at 12:34:50 Pacific
Subject: Form to email page link...
OS: XP Home SP2
CPU/Ram: PIII/123
Model/Manufacturer: HP Pavilion
Comment:

I have a function on my websites called "Tell-a-Friend" which allows the viewer to click a link, a form opens up, they enter a friend's email address, click SEND, and the friend recieves an email with a link to the webpage they were viewing. This is useful in the real estate market, which is how I use it. My Tell A Friend recently quit working, but I don't know why. It's a PHP code I copied from a site which apparently doesn't exist anymore.
Does anyone know of this function and how it works? Or another one like it? I found a bunch of sites that want me to pay about $10 a month for it, but that seems crazy when I know it was working before, and it was free.

Any advice would be appreciated....



Report Offensive Message For Removal


Response Number 1
Name: Michael J (by mjdamato)
Date: March 12, 2007 at 20:37:36 Pacific
Subject: Form to email page link...
Reply: (edit)

That's a pretty easy thing to do. Why don't you post the code you have now.

Michael J


Report Offensive Follow Up For Removal

Response Number 2
Name: jinx
Date: March 17, 2007 at 23:09:36 Pacific
Subject: Form to email page link...
Reply: (edit)

OK -
First, I put a link in my webpage like, "href="http://www.mysite.com/tell_a_friend/index.php"

Then I upload the index.php and settings.php to a folder "tell_a_friend" on my host. (Does it matter that it's a Windows server??)

I hadn't changed the index.php or settings.php when it stopped working. The only thing I can think of that changed, is that I moved to a different server. I don't know anything about PHP, except that I used it in this case to perform a needed function.

Here's the index.php:

<?php
include('settings.php');
// If they submitted the form
if ($Submit=="Submit"){

//****************************************************************************************************
function check_email($email) {
if( (preg_match('/(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/', $email)) ||
(preg_match('/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/',$email)) ) {
return true;
}
return false;
}
//****************************************************************************************************

// Retrieve all the info
$pageurl = $_POST["pageurl"];
$in_name = $_POST["name"];
$in_email = $_POST["email"];
$in_count = $_POST["count"];
$in_message = $_POST["message"];


// Loop through the recipients email, only count the valid ones
for ( $count=1; $count<=$in_count; $count++ ){
$email = $_POST["friend_" . $count];
if ( check_email($email) ){
$to_emails[$count] = $email;
$bcc .= "$email";
if ($count != $in_count){
$bcc .=", ";
}
}
}

// Validate the info
if ( empty($in_name) ){ $error="yes"; $log[] = "$msg_name"; };
if ( empty($in_message) ){ $error="yes"; $log[] = "$msg_message"; };
if ( !check_email($in_email) ){ $error="yes"; $log[] = "$msg_email"; };
if ( empty($to_emails[1]) ){ $error="yes"; $log[] = "$msg_recipient"; };


// Start forming the email

$mail_from = "$in_email";
$mail_replyto = "$in_email";
$mail_bcc = $bcc;

$mail_headers = "From: $in_name <$mail_from>\r\n";
$mail_headers .= "Reply-to: $mail_replyto\r\n";
$mail_headers .= "Bcc: $mail_bcc";

$mail_subject = "$subject";

$mail_message = "The following Virtual Tour was sent to you by $in_name\n";
$mail_message .= "Click here:\n";
$mail_message .= "$pageurl \n\n";
$mail_message .= "$in_message";

if ( $error != "yes" ){ // If there are no errors, send the email(s)
if ( mail($mailto, $mail_subject, $mail_message, $mail_headers) ){
$log[] = "$msg_success";
}else{
$log[] = "$msg_failure";
}
}

}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title><? print $setting_title; ?></title>
<style type="text/css">


</body>
</html>

Here's the settings.php:


<?php

// Be sure when editing the following, you keep the words surrounded by double quotes, and ending in a semicolin if that's the way it was.
// FOLLOW THE PATTERN!

// message reported if they didn't fill in a valid name
$msg_name = "Your name is required";
// message reported if they didn't fill in a valid message
$msg_message = "A message is required";
// message reported if they didn't fill in a valid email
$msg_email = "Your email address is not valid";
// message reported if they didn't fill at least one valid recipient
$msg_recipient = "At least one recipient email is required";
// message reported if they try to add too many recievers
$msg_toomuch = "If you want to tell the whole world, dont do it all at once please";

// message reported if the emails were successfully sent
$msg_success = "Your messages have been sent! Please go back to the tour page.";
// message reported if the emails were NOT successfully sent
$msg_failure = "Your messages could not been sent!";

// What the emails subject will be
$subject = "Check out this Virtual Tour";

// The maximum nuber of recievers, 15 is recomended
$setting_limit = 10;
// The title of the tell-a-friend page
$setting_title = "Show-A-Friend";

?>


Any ideas??

-jinx


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Form to email page link...

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




How often do you use Computing.Net?

Every Day
Once a Week
Once a Month
This Is My First Time!


View Results

Poll Finishes In 3 Days.
Discuss in The Lounge