In PHP there are two routes to take for developing your own mail client.
The first is using the IMAP function library.
The IMAP function library is an extra module and must be compiled into PHP before the functions will be available. (or activated in PHP.ini in Windows and provided the correct path to the .dll).
Don't be fooled by the name, this set of functions may be used to access IMAP, POP3 or NNTP mail protocols.
Read more about IMAP here:
http://www.php.net/imap
The second route is designing custom mail handling functions. Which would require setting up sockets and sending specific commands to the mail server. This would be the most time consuming and most portable approach as the top method requires the c-client module to be installed on the server.
You can run a check to see if the server already has the IMAP module installed by running phpinfo().
As Nik mentioned it's a rather time consuming process to create your own mail client. There are loads of tutorials out there that utilize either method. Just do a google search or use one of the many already built mail clients out there.
Here are a couple of functions that I wrote using the IMAP module.
Code:
<?php
# array imap_connect(void)
#
# http://www.php.net/imap_open
# The imap_open function may be used to open a connection to the mail server
#
function imap_connect() {
$mail = array();
/*
* for pop3: {www.server.com:110/pop3/notls}INBOX
* and for imap: {www.server.com:143/notls}INBOX.
*
*/
$mailbox_server = "{mail.yourserver.com:110/pop3/notls}INBOX";
$mail["connection"] = @imap_open($mail_data["mailbox_server"], $mail_data["mailbox_user"], $mail_data["mailbox_password"]);
imap_error_message($mail["connection"]);
return $mail;
}
# bool close_imap_connection(array mail components)
#
# imap_close closes the mail connection
# http://www.php.net/imap_close
#
function close_imap_connection($mail) {
if (!@imap_close($mail["connection"])) {
echo "Error: unable to close mail connection.<br />\n";
return false;
} else {
return true;
}
}
# bool imap_error_message(resource handler)
#
# imap_errors(), imap_alerts()
# display any errors brought back from the mail server
# http://www.php.net/imap_errors
# http://www.php.net/imap_alerts
function imap_error_message($result) {
if (empty($result)) {
$errors = imap_errors();
$alerts = imap_alerts();
if (is_array($alerts)) {
for ($i = 0; each($alerts); $i++) {
if (isset($alerts[$i])) {
echo $alerts[$i]."<br />\n";
}
}
}
if (is_array($errors)) {
for ($i = 0; each($errors); $i++) {
if (isset($errors[$i])) {
echo $errors[$i]."<br />\n";
}
}
}
return true;
}
return false;
}
# int imap_message_count(void)
#
# imap_num_msg - returns the message count
# http://www.php.net/imap_num_msg
#
function imap_message_count() {
$mail = imap_connect();
if (!$message_count = @imap_num_msg($mail["connection"])) {
$message_count = "0";
}
close_imap_connection($mail);
return $message_count;
}
echo "You have ";
echo imap_message_count();
echo " messages total!";
?>
I haven't checked for errors, I just did a breif modification of functions that I already use! Let me know if you have any more questions with specific components and I'll do my best to help out.
Best of luck!
: )
Rich
:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::