rachae1 Posted July 25, 2008 Share Posted July 25, 2008 Hi I am trying to put together a script for a tell a friend I have used two different scripts to make what I have now and I am now stuck and was wondering if anyone can help. I would like to use this code in a popup window so that when a user clicks the button tell a friend it then loads up and when they press submit it emails the friend the page link. All is working ok apart from it echos the url that the form is in and not the previous page. Does anyone know how I can get it to do this. Thanks in advance <?php session_start(); if ($fromEmail) { $ref=$_SERVER['HTTP_REFERER']; if ($fromName=='') $subject= "Your friend has referred you this link from www.glitzybingo.co.uk"; else $subject= "$fromName has referred you this link from www.glitzybingo.co.uk"; $message = " Dear $toName, Your friend $fromName has referred this link to you. Please visit this link by clicking $ref "; $from = "From: $fromEmail\r\n"; mail($toEmail, $subject, $message, $from); header ("location:".$ref); } if( isset($_POST['submit'])) { header('Location: thepage.php'); if( $_SESSION['security_code'] == $_POST['security_code'] && !empty($_SESSION['security_code'] ) ) { echo 'thanks'; unset($_SESSION['security_code']); } else { // Insert your code for showing an error message here echo 'Sorry, you have provided an invalid security code'; } } else { ?> <form method="POST"> <input type="hidden" name="redirect"> <td align="center" valign="middle"><table width="600" border="0" cellspacing="0" cellpadding="0"> <tr> <td height="30" colspan="2"><strong>Your Details</strong></td> </tr> <tr> <td height="30">Name: <input name="fromName" type="text" id="fromName"></td> <td height="30">E-Mail: <input name="fromEmail" type="text" id="fromEmail"></td> </tr> <tr> <td height="30" colspan="2"><strong>Friends Details</strong></td> </tr> <tr> <td height="30">Name: <input name="toName" type="text" id="toName"></td> <td height="30">E-Mail: <input name="toEmail" type="text" id="toEmail"></td> </tr> <tr align="center"> <td height="30" colspan="2"><input type="submit" name="Submit" value="Refer"></td> </tr> </table></td> <img src="CaptchaSecurityImages.php?width=100&height=40&characters=5" /><br /> <label for="security_code">Security Code: </label><input id="security_code" name="security_code" type="text" /><br /> <input type="submit" name="submit" value="Submit" /> </form> <?php } ?> Link to comment https://forums.phpfreaks.com/topic/116582-solved-tell-a-friend-script-help/ Share on other sites More sharing options...
rachae1 Posted July 25, 2008 Author Share Posted July 25, 2008 Just updated my code as I realised I had two submit buttons that seemed to do the same thing removed one of them. <?php session_start(); if ($fromEmail) { $ref=@$HTTP_REFERER; if ($fromName=='') $subject= "Your friend has referred you this link from www.glitzybingo.co.uk"; else $subject= "$fromName has referred you this link from www.glitzybingo.co.uk"; $message = " Dear $toName, Your friend $fromName has referred this link to you. Please visit this link by clicking $ref "; $from = "From: $fromEmail\r\n"; mail($toEmail, $subject, $message, $from); header ("location:".$ref); } if( isset($_POST['submit'])) { header('Location: thepage.php'); if( $_SESSION['security_code'] == $_POST['security_code'] && !empty($_SESSION['security_code'] ) ) { echo 'thanks'; unset($_SESSION['security_code']); } else { // Insert your code for showing an error message here echo 'Sorry, you have provided an invalid security code'; } } else { ?> <form method="POST"> <input type="hidden" name="redirect" value="http://www.glitzybingo.co.uk"> <td align="center" valign="middle"><table width="600" border="0" cellspacing="0" cellpadding="0"> <tr> <td height="30" colspan="2"><strong>Your Details</strong></td> </tr> <tr> <td height="30">Name: <input name="fromName" type="text" id="fromName"></td> <td height="30">E-Mail: <input name="fromEmail" type="text" id="fromEmail"></td> </tr> <tr> <td height="30" colspan="2"><strong>Friends Details</strong></td> </tr> <tr> <td height="30">Name: <input name="toName" type="text" id="toName"></td> <td height="30">E-Mail: <input name="toEmail" type="text" id="toEmail"></td> </tr> <tr align="center"> <td height="30" colspan="2"></td> </tr> </table></td> <img src="CaptchaSecurityImages.php?width=100&height=40&characters=5" /><br /> <label for="security_code">Security Code: </label><input id="security_code" name="security_code" type="text" /><br /> <input type="submit" name="submit" value="Submit" /> </form> <?php } ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/116582-solved-tell-a-friend-script-help/#findComment-599479 Share on other sites More sharing options...
rachae1 Posted July 25, 2008 Author Share Posted July 25, 2008 :-\ Link to comment https://forums.phpfreaks.com/topic/116582-solved-tell-a-friend-script-help/#findComment-599734 Share on other sites More sharing options...
rachae1 Posted July 25, 2008 Author Share Posted July 25, 2008 Ok kind of solved it. The form was originally submitting the current url instead of the reffering url so I have created a new field <input name="refurl" type="text" id="refurl" value="<?php echo $_SERVER['HTTP_REFERER']; ?>"></td> So incase anyone wants to play with the tellafriend script with themselves heres the below code: <?php if ($fromEmail) { $ref=@$HTTP_REFERER; if ($fromName=='') $subject= "Your friend has referred you this link from www.sitename.com"; else $subject= "$fromName has referred you this link from www.sitename.com"; $message = " Dear $toName, Your friend $fromName has referred this link to you. Please visit this link by clicking $refurl"; $from = "From: $fromEmail\r\n"; mail($toEmail, $subject, $message, $from); header ("location:".$ref); } if( isset($_POST['submit'])) { header('Location: thepage.php'); if( $_SESSION['security_code'] == $_POST['security_code'] && !empty($_SESSION['security_code'] ) ) { echo 'thanks'; unset($_SESSION['security_code']); } else { // Insert your code for showing an error message here echo 'Sorry, you have provided an invalid security code'; } } else { ?> <form method="POST"> <input type="hidden" name="redirect"> <input type="hidden" name="fromemail" value="<?php echo $_SERVER['HTTP_REFERER']; ?>" /> <td align="center" valign="middle"><table width="600" border="0" cellspacing="0" cellpadding="0"> <tr> <td height="30" colspan="2"><strong>Your Details</strong></td> </tr> <tr> <td height="30">Name: <input name="fromName" type="text" id="fromName"></td> <td height="30">E-Mail: <input name="fromEmail" type="text" id="fromEmail"></td> </tr> <tr> <td height="30" colspan="2"><strong>Friends Details</strong></td> </tr> <tr> <td height="30">Name: <input name="toName" type="text" id="toName"></td> <td height="30">E-Mail: <input name="toEmail" type="text" id="toEmail"></td> </tr> <input name="refurl" type="text" id="refurl" value="<?php echo $_SERVER['HTTP_REFERER']; ?>"></td> </table></td> <img src="CaptchaSecurityImages.php?width=100&height=40&characters=5" /><br /> <label for="security_code">Security Code: </label><input id="security_code" name="security_code" type="text" /><br /> <input type="submit" name="submit" value="Submit" /> </form> <?php } ?> Link to comment https://forums.phpfreaks.com/topic/116582-solved-tell-a-friend-script-help/#findComment-599763 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.