<?php
// Have a button/link ("Send message") on the member profile. When clicked, it has to fetch the "email_address" of that member from the respective table. Assign it to $to_address.
$to_address="address_of_the_recipient";
if(isset($_REQUEST['submit'])){
$subject=$_REQUEST['subject'];
$message=$_REQUEST['message'];
$headers = 'From: Naveen < >' . "\r\n";
mail($to_address, $subject, $message, $headers);
echo "Message sent successfully..";
} else {
?>
<html>
<body>
<FORM METHOD=POST ACTION="mail.php">
Subject: <INPUT TYPE="text" NAME="subject" size="30">
Message: <TEXTAREA NAME="message" ROWS="10" COLS="20"></TEXTAREA>
<INPUT TYPE="submit" name="submit" value="submit">
</FORM>
</body>
</html>
<?php
}
?>
The above code has not been checked for sanity, but it does what it has to.
Cheers,
Nav
nav33n
Purple hazed!
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
I'm not familiar with the way Hotornot or Hi5 do it. Do you receive actual emails in your mailbox, or is it just notifications of Private messages from other users?
The easy way, is to have a private messaging system, and then notify users via email of new messages, and have them click on a a link to view the message and reply. So no emails are exchanged. The only email address is the one used to send out the message from your server (you could use [email]no-reply@yourwebsite.com[/email] or something similiar).
The other way would be to create an email address for each user on your site. You could have this be: [email]username@yoursite.com[/email]. Then each message sent to [email]username@yoursite.com[/email] gets redirected to the users actual emails address. This way, the users can email each other on their username generated by your website.
You can also generate a "conversation" email for two users. This is a random email that identifies a conversation (session) between two users.
Say, user1 wants to email user2.
They fill int he form on your site, and your site will forward the email to user2.
It will set the sender as [email]conversation1@yoursite.com[/email]
user2 replies to [email]conversation1@yoursite.com[/email]
your server receives an email from user2 addressed to [email]conversation1@yoursite.com[/email]
Your server forwards this to user1 setting the sender as [email]conversation1@yoursite.com[/email]
The trick is that you've assigned an email that is on your domain, so all emails between the two have to pass through your email server. So there you make the changes.
There are other methods.
Every method requires you to be able to receive incoming emails, and create email accounts on your server.
With PHP you can receive emails by connecting to your mailserver via POP3 or IMAP and download all new mails in your mailbox.
You can also create a mail pipe to your PHP script. This is done by editing your mail forwards and placing a PHP script as the forwarding address. Some of this can get very technical and dependent on the mailserver (MTA) used. Using POP3 or IMAP is simpler, but a pipe has the benefit that incoming mail is processed in real time.
Once you receive emails, you'll need a MIME parser that will parse out the senders and receivers address and make the necessary changes. There is a good mime parser at PEAR.
digital-ether
Nearly a Posting Virtuoso
1,293 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101
Interesting. How can a private messaging system be built? Do you have the software script please? I will be very grateful if you tell me about it.
A PM system is very simple. The simplest being:
1 db table. Say its called private_messages.
You then create a form that allows users to send private messages to other users.
On the form you need the user to input the username, and message they want to send.
So in your db table you'll have:
id, from, to, message, as the columns.
Id will be the primary key (unique index).
So when the user submits the form, you will save the from, to and msg fields in the database.
You then create 2 views for private messages. I being the list view, which views private messages for a user. And the message view, which views the individual messages.
eg:
$username = mysql_real_escape_string($_SESSION['username']); // from session
$query = "SELECT * from private_messages where to = '$username'";
where $_SESSION['username'] is the username of the logged in user.
Thats for list view.
Then view message view, you should get a message id from the URL, when the user licked on a single message in the list view.
$id = intval($_GET['id']); // from URL
$username = mysql_real_escape_string($_SESSION['username']); // from session
$query = "select * from private_messages where id=$id and to = '$username' LIMIT 1";
and of course theres the compose message view. Which is the form mentioned ...
There are many Private Messaging systems implemented in different web based apps, like this forum for instance. Just view how the interface is created and how the views are laid out to get an idea.
You can also download PM systems for some open source software, and look at the code.
digital-ether
Nearly a Posting Virtuoso
1,293 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101
There are quite a few social networking scripts out there. But I would recommend going with a Content Management System. (Unless you want something very specific).
I use Joomla, (joomla.org), then install the extensions that make it function like a social networking site. Like: Community Builder, Private Messaging Extensions, Friends extensions etc. You can get these from http://extensions.joomla.org/
Their forum will also help you out if you go with Joomla.
digital-ether
Nearly a Posting Virtuoso
1,293 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101