p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Beginning PHP (http://p2p.wrox.com/forumdisplay.php?f=95)
-   -   Email handling (http://p2p.wrox.com/showthread.php?t=4807)

rajanikrishna October 10th, 2003 02:42 AM

Email handling
 
Hi friends,

    In the Begining PHP text book it was given how to send emails and attachemnts. But how can i manage Inbox and how to create users and limiting each user to 2MB space. How to retrieve mails from Inbox and other folders.

Pls give me the solution.


nikolai October 10th, 2003 12:07 PM

That's a pretty tall order you're asking... I mean, if I were hired to write that application, I'd charge time and materials and estimate that it'd take no less than a full month (40 hrs a week) to complete.

I suggest you look at online code repositories for a web-based email client written in PHP, and look through their documentation and source code.

The first thing you need to do is realize that PHP itself can't create users for you, not unless you give your PHP script root/administrator access on the machine you're creating users. The PHP application will simply access someone's existing mail box.

Here's a couple links to get you started.

  http://www.google.com/search?q=php+w...d+email+client
  http://www.hotscripts.com/PHP/Script...b-based_Email/


Take care,

Nik
http://www.bigaction.org/

richard.york October 10th, 2003 01:39 PM

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
:::::::::::::::::::::::::::::::::

richard.york October 10th, 2003 01:44 PM

Ah Shizzle,
I missed a few keypoints on this:

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($mailbox_server, "mail_user", "mail_password");

            imap_error_message($mail["connection"]);

        return $mail;

    }

You might have noticed this error:
$mail_data["mailbox_server"] was supposed to be $mailbox_server.
I used database output in my original function and forgot to modify that but I'm sure you see what's supposed to be happening there.

: )
Rich

:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::


All times are GMT -4. The time now is 03:10 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.