Wrox Programmer Forums
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 10th, 2003, 02:42 AM
Friend of Wrox
 
Join Date: Sep 2003
Posts: 363
Thanks: 0
Thanked 1 Time in 1 Post
Default 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.

 
Old October 10th, 2003, 12:07 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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/
 
Old October 10th, 2003, 01:39 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

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
:::::::::::::::::::::::::::::::::
 
Old October 10th, 2003, 01:44 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
SMTP Email Error Handling Ron Howerton Pro Visual Basic 2005 1 July 12th, 2007 08:32 AM
exception handling jay schumacher VB.NET 2002/2003 Basics 1 April 14th, 2006 08:40 AM
session handling meenakshi.sharma84@gmail. PHP How-To 1 April 12th, 2006 03:08 AM
erron handling garrydawkins SQL Server 2000 1 April 10th, 2006 03:44 PM
Incoming Email handling BaNSHee SQL Server ASP 0 April 6th, 2005 05:00 AM





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