Forum Moderators: coopster
I ve built a custom website from scratch in php. I am now trying to add a mail feature that allows registered users of the site to send email to other registered users of the site WITHIN my site (meaning they don't leave my site). I have no idea how to start.
I am wondering if I can use an open source script that would integrate nicely to my website, but have no idea where to look.
If I were to try and build this feature from scratch myself, how should I go about it? Please, any suggestions, advice, or tips are welcome. Thanks a bunch!
ID, to, from, subject, content, dateTime
(ID is auto incrementing, and unique)
A person's inbox can then be (with the appropriate table formatting etc, break tags just for a working example):
if(!isset($_GET['newsid']) || $_GET['newsid'] == "") {
$sql = 'SELECT * FROM mail_table WHERE to="' . $_SESSION['user'] . '" ORDER BY dateTime ASC';
$result = mysql_query($sql);
$rows = mysql_num_rows($result);
if($rows > 0) {
for($i = 0; $i < $rows; $i++) {
$from = mysql_result($result,$i,"from");
$subj = mysql_result($result,$i,"subject");
$dati = mysql_result($result,$i,"dateTime");
$id = mysql_result($result,$i,"ID");
echo '<a href="/myinbox.php?newsid=' . $id . '">' . $dati . ' : ' . $subj . '</a> From ' . $from . '<br />';
}
} else {
echo 'You have no mail in your inbox';
}
} else {
$sql = 'SELECT * FROM mail_table WHERE ID="' . mysql_real_escape_string($_GET['newsid']) . '"';
$result = mysql_query($sql);
$from = mysql_result($result,0,"from");
$subj = mysql_result($result,0,"subject");
$dati = mysql_result($result,0,"dateTime");
$cont = mysql_result($result,0,"content");
echo 'From: ' . $from . '<br />' . $dati . ' : ' . $subj . '<br />' . $cont;
} Should work quite nicely.
[edited by: Readie at 11:10 pm (utc) on Jan. 29, 2010]
sending the mail be:
if(isset($_GET['action']) && $_GET['action'] == "sendmail") {
$dateTime = date(r);
$from = $_SESSION['user'];
$to = mysql_real_escape_string($_POST['to']);
$subj = mysql_real_escape_string($_POST['subject']);
$cont = mysql_real_escape_string($_POST['content']);
$sql = 'INSERT INTO mail_table (from, to, subject, dateTime, content)
VALUES("$from", "$to", "$subject", "$dateTime", "$content")';
mysql_query($sql) or die('Could not connect to server');
echo 'Message sent to ' . $to . ' at ' . $dateTime . '.';
} else {
echo '<form method="POST" action="/mail.php?action=sendmail">
To: <input type="text" name="to" /><br />
Subject: <input type="text" name="subject" /><br />
<textarea name="content"></textarea><br />
<input type="submit" value="Send mail" />
</form>';
}