Page 1 of 1

Making a webmail system | PHP | Part 1 Rate Topic: -----

#1 jonesa01  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 25
  • View blog
  • Posts: 125
  • Joined: 18-February 07

Posted 07 December 2011 - 01:57 AM

Tutorial: making a webmail system in PHP
Welcome to the first in a series of tutorials in which I will talk about how to make a basic webmail system with PHP and MySQL.

The finished system will have the following system:

- Retrieve e-mails from a specified e-mail account
- Show all the mailboxes for the account
- Retrieve and save e-mail attachments
- Save all e-mails to a database for security
- Have a preview screen below the e-mail listings
- Compose e-mail function
- The ability to delete, reply and forward messages

I will go through it at a steady pace while explaining things thoroughly and giving you the code, breakdowns and links to the php site about the functions used.

Tutorial Part 1 – Server Setup

For this system you will need a PHP server, a SMTP/IMAP server (or Gmail etc.) and a MySQL database.

Step 1: setup the location where you will make the script either a subdomain or a folder. This depends on your host and where you want people to access the facility.

Step 2: setup your database, I advise you if possible to have a separate database to make sure the e-mail data is secure as possible. Keep the server url, username, password and database handy as you will need them throughout this and the next part of this tutorial.

Step 3: add the initial database tables to the database using the sql code below. In this example it will store both the e-mail address/username and password (encrypted) in a database and store all the e-mails in another. The other table will store all the mailboxes for each e-mail address so the webmail can be loaded without connecting to the mail server if you wanted.

SQL: users table – stores email addresses and passwords

CREATE TABLE `users`(
`ID` INT(250) NOT NULL AUTO INCREMENT,
`Email` VARCHAR(250) NOT NULL,
`Password` VARCHAR(250) NOT NULL,
Primary key(`ID`));



SQL: mailbox table – stores all the mailboxes for a user uses user ID as a secondary key

CREATE TABLE `mailboxes`(
`ID` INT(250) NOT NULL AUTO INCREMENT,
`Name` VARCHAR(250) NOT NULL,
`UserID` INT(250) NOT NULL,
Primary key(`ID`));



SQL: message table – stores all the messages for each user stores Mailbox ID as a secondary key

CREATE TABLE `messages`(
`ID` INT(250) NOT NULL AUTO INCREMENT,
`To` VARCHAR(250) NOT NULL,
`CC` VARCHAR(250),
`BCC` VARCHAR(250),
`From` VARCHAR(250) NOT NULL,
`Subject` VARCHAR(250),
`Message` LONG BLOB NOT NULL,
`Date` DATETIME NOT NULL,
`MailboxID` INT(250) NOT NULL,
Primary Key (`ID`));



I have not covered the database for the attachments as that will come in later on in the tutorial series when we get to the stage of working with attachments.

Step 4: setup the folders you will need – below is the basic file organisation you will need:

#Root
Classes/
Mail/
Template/

End of Tutorial 1

I have not covered much in this tutorial but the aim is to get the foundations together so we are ready to build on the script.

Next Time…

In the next tutorial I will be concentrating on the database class and running a script to test it before we get down to the real code on this project.

Until next time..

Is This A Good Question/Topic? 2
  • +

Replies To: Making a webmail system | PHP | Part 1

#2 kumaraj  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 3
  • View blog
  • Posts: 78
  • Joined: 12-February 09

Posted 30 December 2011 - 02:45 PM

When is the next part of this tutorial coming out, I would be interested to see if the way that you set up your mail thingy ma bob is the same way that I would do mine. I hope I don't have to wait too long.
Was This Post Helpful? 0
  • +
  • -

#3 jonesa01  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 25
  • View blog
  • Posts: 125
  • Joined: 18-February 07

Posted 02 April 2012 - 02:23 AM

Sorry for the delay in getting part 2 up. It is avaliable here: Part 2
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1