send a friend client side
Hi,
I would like to include a link on a page "send a friend". When a visitor clicks on the link he/she is redirected to a page with a form where he/she can leave the name and e-mail address of their friend and their own details. Then the sender should get a confirmation and the friend receives a standard message with a link to the specific page.
So need two things:
1. script on the page of the link (which remembers the url to the next page)
2. script for sending the message
Who can help?
cheers,
Pieter
This link will redirect to a page named sendMail.php with the current url. You need to use a server side language to actually send the mail.
HTML Code:
<a href="#" onclick="location.href='sendMail.php?url='+location.href;" > Send to a friend</a>
O.K., I quickly copied this from one that I use. See how it works for you.
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Recommend This Web Site to a Friend</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<style type="text/css">
<!--
input.button {
color: #000;
background: #decfbd;
font-size: small;
font-weight:bold;
font-family: Verdana, Arial, Helvetica, sans-serif;
border: solid 1px #000;
}
body {
margin: 0;
padding; 0;
background-color: #dfd7c3;
}
td {
font: bold .8em verdana, arial, sans-serif;
}
td.right {
text-align: right;
vertical-align: top;
}
.credits {
font: bold .6em verdana, arial, sans-serif;
margin-left: 50px;
}
-->
</style>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_validateForm() { //v4.0
var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
if (val) { nm=args[i+1]; if ((val=val.value)!="") {
if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
} else if (test!='R') { num = parseFloat(val);
if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
min=test.substring(8,p); max=test.substring(p+1);
if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
} if (errors) alert('The following error(s) occurred:\n'+errors);
document.MM_returnValue = (errors == '');
}
// form focus
function putFocus(formInst, elementInst) {
if (document.forms.length > 0) {
document.forms[formInst].elements[elementInst].focus();
}
}
//-->
</script>
</head>
<body onLoad="putFocus(0,0);">
<?php
$websiteAddy = "webSite@address.com";
if (!$FriendEmail) {
?>
<br>
<form name="form1" onsubmit="MM_validateForm('Name','Your name','R','Email','Your e-mail address','RisEmail','FriendName','Your friend\'s name','R','FriendEmail','Your friend\'s e-mail address','RisEmail');return document.MM_returnValue" action="" method="POST">
<table border="0" cellspacing="0" cellpadding="3">
<tr>
<td colspan="3" style="text-align: center;">Name</td>
<td>E-mail</td>
</tr><tr>
<td class="right">You:</td>
<td colspan="2"><input type="text" name="Name" size="15"></td>
<td><input type="text" name="Email" size="20"></td>
</tr><tr>
<td class="right">Friend:</td>
<td colspan="2"><input type="text" name="FriendName" size="15"></td>
<td><input type="text" name="FriendEmail" size="20"></td>
</tr><tr>
<td class="right">Message:</td>
<td colspan="4">
<textarea name="emailtext" cols="40" rows="6" style="font-family: Trebuchet MS; font-size: 10pt">
I found this great Web site and I believe you will be interested in it. Here is the link to the page: <?php echo $QUERY_STRING ?>
</textarea>
</td>
</tr><tr>
<td colspan="4" style="text-align: right;">
<input class="button" type="submit" value="Send" name="Submit">
</td>
</tr>
</table>
</form>
<?php
}
else {
$myemail = "$Email";
$mailheaders = "From: $websiteAddy" \n";
if ($FriendEmail) {
mail( $FriendEmail, "Message from $Name", "$FriendName, \n\n".$emailtext ."\n\n$Name", "From: $Email");
mail ( $myemail, "Someone used Tell-A-Friend", "$Name, your recommendation to $FriendName at $FriendEmail has been sent.".$emailtext, $mailheaders );
}
echo "<br><br>
<p style='margin-left: 50px;'>Thank you $Name.<br><br>Your e-mail has been sent to $FriendName.</p>
<br><br<br>
<p style='margin-left: 50px;'><a href='javascript :window.close();'>Close this window</a></a>
<br><br><br>
<p class='credits'>
powered by: <a href='http://www.simplewebsols.com\/phpscripts.php'>simple sendtofriend</a></p>";
}
?>
</body>
</html>
In the page you want to call it from, place this in the head section:
Code:
function newWindow(mypage,myname,w,h,features) {
if(screen.width){
var winl = (screen.width-w)/2;
var wint = (screen.height-h)/2;
}else{winl = 0;wint =0;}
if (winl < 0) winl = 0;
if (wint < 0) wint = 0;
var settings = 'height=' + h + ',';
settings += 'width=' + w + ',';
settings += 'top=' + wint + ',';
settings += 'left=' + winl + ',';
settings += features;
win = window.open(mypage,myname,settings);
win.window.focus();
}
Then call it with:
Code:
<a href="javascript :newWindow('/sendemail.php?'+'http://www.yourSite.com/','email',400,300,'')" style="text-decoration: none;">
• recommend this site!
</a>
The original creator is listed in the credit at the bottom.
Lee
"
"Men occasionally stumble over the truth, but most of them pick themselves up and hurry off as if nothing ever happened." " -- Sir Winston Churchill
Hi,
Thanks foor the quick replies... I'll try the sollutions 2morrow!
Cheers,
Pieter
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Bookmarks