Home N-13 News Forums Help Search
RegisterForgot password?
How to add image to post necklacesdiscou
Known bugs - 4.0.3 necklacesdiscou

Latest N-13 News 4.0.3

What is N-13 News?
Where can I get help?
Known bugs

Forums Help & Support Allow guests to private message you
Chris
Posted on 30 May 2008, 00:50:28

Access: Admin
Total Posts: 1395
Joined: 2006-05-19

Pretorian asked about a feature I never really thought of before, allowing guests to your site to private message you without having an account. The solution I came up with was very simple, create a dummy account in the system, for this example I named it Guest, and create a script that private messages you using the new guest account. It doesn't matter what the email and password for this account is, just make sure you choose a decent password which can't be guessed.

The following script does that. I purposely left the form as minimal as possible so it could be easily edited. The only thing that needs to be changed is the account the message will be sent to '$sendto'

When a message gets sent to you the title will be 'New message from {username of guest}', and the message will show the guests email address and message.


Code:
<?php
include 'db.php';
include 
'config.php';
$sendto = 'Chris'; #put your username here
function showguestform(){
?>
<form method="post" action="">
Name: <input type="text" name="guestname" value="<?php echo htmlentities($_POST['guestname']); ?>" /><br />
Email: <input type="text" name="guestemail" value="<?php echo htmlentities($_POST['guestemail']); ?>" /><br />
Message: <textarea name="guestmessage"><?php echo htmlentities($_POST['guestmessage']); ?></textarea><br />
<input type="submit" name="guests1" value="Send message" />
</form>
<?php 

}

if(!
$_POST['guests1']){
    
showguestform();
}else{
    if(!
$_POST['guestname']){
        echo 
"Please enter your name<br />";
        
showguestform();
    }elseif(!
$_POST['guestemail']){
        echo 
"Please enter your email address<br />";
        
showguestform();
    }elseif(!
$_POST['guestmessage']){
        echo 
"Please enter a message<br />";
        
showguestform();
    }else{
        
$guestid = getresult("SELECT uid FROM $newsusers WHERE user = 'Guest'");
        
$title = "New message from " . slash2($_POST['guestname']);
        
$message = "Email address: " . slash2($_POST['guestemail']) . "\n\r\n\r" . slash2($_POST['guestmessage']);
        
$sentfrom = $guestid;
        
$sentto = getresult("SELECT uid FROM $newsusers WHERE user = '$sendto'");
        
$viewed = 1;
        
$posted = time();
        
$sql = "INSERT INTO $newsprivate (title,message,sentfrom,sentto,viewed,posted) VALUES ('$title','$message','$sentfrom','$sentto','$viewed','$posted')";
        
$query = mysql_query($sql) or die(mysql_error());
        
        echo 
"Your message has been sent";
    }    
}
?>
#216
Last edited by Chris at 2008-05-30 01:15:13 Reason:
Network-13.com © 2013