26

I would like to learn how to build a web-based email client in PHP (similar to yahoo and gmail).

Does anyone know how I can get started with this?

I would like my system to be able to send and receive email.

Robert Greiner
  • 27,214
  • 9
  • 63
  • 85
panidarapu
  • 8,031
  • 6
  • 24
  • 24

8 Answers8

85

Most obvious answer would be "don't" : there are already lots of webmail software, some of which are PHP-based (if you depend on using PHP, because you already have a server based on a LAMP stack, for instance).

To quote only a few names, all PHP-based, you could have a look at these ones :

  • SquirrelMail : a quite old-one, and not really sexy... But has been doing the job for years
  • Horde IMP : well-know too, and quite powerful
  • roundcube : maybe the most "sexy" and "web 2.0" of the list of those I tried
  • AtMail : I've never used this one, so I can't say much more...

I've used the three firsts of the list for quite some time ; roundcube was definitly the most "user-friendly", I'd say...

(Googling a bit, you might find many more -- but I think I spoke about the ones that are the most used)


Now, if you have to set up a Webmail, say, for you company : definitly use some already existing software :

  • an existing software would be quite "good" already :
    • many people using it, which means many people who said "this could be done better", or "that is not user-friendly", or... you get the point ; all this made the existing software better :-)
    • many people will have tried to break such an application -- which means lots of security-fixes, which means an application probably more secure than you'll write in a long time...
  • an existing open-source application will represent hundreds of days of work
    • are you really ready to spend that kind of amount of time working on something that already exists ?
    • if you're working for a company : is your company ready to pay your for one year ? or even probably more ? working on something that already exists ?
    • you don't believe me ? Read this blog-post : Code: It's Trivial ; it's about stackoverflow, but it would be exactly the same for a webmail software (except that stackoverflow is more recent -- and probably had less code-contributors ; but that's just a wild guess ^^ )

As a sidenote : if your company wants you to build a clone of gmail, you won't (same thing : how many people worked on gmail ? How many programmers does your company have ? How much can your company spend on this ? )...
And for just a couple dollars each year, your company could have a "professionnal" Google account for each one of it's employes, btw...


After all this, if you still want to / have to write a custom hand-made webmail using a LA*(M)*P stack, you will need to know at least the following :

  • How to programm in PHP
  • The basics of IMAP (even if you use a library / framework, such a big application will require you to know some stuff about the underlying protocols, or won't ever understand "why" or "how" something went wrong)
  • HTML / CSS / Javascript (with some knowledge of AJax -- come on, it's 2009 !)
  • So your application is easier to maintain (and adding/reworking/modifying stuff and correcting bugs is possible), you will probably want to use some Framework, and follow some design patterns and best practices
    • As an example, you can take a look at Frameworks like symfony, or Zend Framework
    • Yes, you can develop and application without a Framework, and/or without MVC... But.. ergh...

Considering all this is not a problem (If you are not quite good at all this already, and/or don't have much experience, it could take at least a couple of years to acquire that... Considering programming and web-developping is your full-time activity), you can start tkinking about accessing a mail server using, for instance, IMAP.

There are several possibilities here.
I would have a look, at least, before choosing, at these two :


Once your application is quite done, you will (hopefully !) start getting users, which means at least three things :

  • Bug-reports ; those are almost always urgent for users -- like "OMG I don't understand nothing works anymore, I gotta get my mail RIGHT NOW!"
  • Requests for evolutions : users always want more stuff like "I saw that in gmail on my personnal account ; how is it we don't have that too with our corporate account ? It's the tool we use to work !"
  • "This is too slow, I can't work !" ; then, pray you thought about scalability and optimization when you designed/developped the application !

Here, again, are you ready to deal with that ?


Well, I think I said enough ; now, it's your time to think : do you really want/need to develop such an application from scratch ?

If you have a bit of free time, maybe you could participate in an already existing, open-source, project ? That could be profitable to every one ;-)


Finally, one last thing : if you want to work on such a project just for fun, to know what it's like, and to learn more about web-development, then DO !
(It's, in my opinion, probably the only reason that would justify working on this, btw)


Anyway, good luck ! And/or have fun !

Pascal MARTIN
  • 374,560
  • 73
  • 631
  • 650
  • The problem is that most email clients are stand-alone. If you want to actually integrate email into your app, then you have a problem. None of the existing solutions integrate well or at all. – Scott M. Stolz May 23 '20 at 16:50
28
  1. Learn the web stack: HTML, javascript, php, mysql...
  2. Write a few small projects
  3. Get hired somewhere to learn from more experienced people
  4. Learn OOP, design patterns, best practices etc
  5. Apply what you learned for a few years

If you pass point 5, you'll know how to build one.

Paul Grigoruta
  • 2,266
  • 1
  • 19
  • 25
7

You can build a simple one quite easily using the PHP IMAP functions but if you have to ask then it might be a bit complicated for you.

Have you considered using a pre-built one:

Greg
  • 295,929
  • 52
  • 357
  • 326
1

Thats a HUGE question!

Your main options are
1. Directly integrating your code with an existing mail server
2. Using IMAP and SMTP to talk to an existing mail server

Number 2 is the most straightforward because you can change mail servers if you ever need to.

and yes there's a lot more to consider as you go

Dave Archer
  • 2,927
  • 18
  • 22
0

Set up an email account that can be accessed via POP (example: gmail). Then use the PHP IMAP functions to retrieve email via the POP protocol (POP is probably easier than IMAP) (http://us2.php.net/imap). For sending mail, use the PHP Mail functions (http://us2.php.net/mail).

pbreitenbach
  • 10,910
  • 3
  • 31
  • 24
0

If you're not using an external mail service (like Gmail) you will need to configure your own server to store and send email. Here is a tutorial for using Postfix (for sending mail) and Dovecot (for accessing mail via IMAP). This tutorial also explains setting up a webmail system in SquirrelMail. You could do this, or, if you really want to develop your own system you could write a PHP application to access your mail.

Good Luck!

DLH
  • 2,611
  • 3
  • 20
  • 30
0

Most obvious answer should be "great".

I agree. With the current so-called-most-sexy interface we're stuck with, it's clear we need something different. For those thinking I like to invent the wheel: I don't! I just installed a new website and I am very satisfied with the result. I basically used 1000s of hours of free developers' work and would hate to re-invent something which has been done before, 1000 times better. I would come up with a website 10% of what I would have right now and would have spend 10 times longer. The layout is great, the functionality is great. I have authentication, a face-book type of social network, private area for me and my family to store files, agenda, photo and video support, youtube integration, facebook integration, ... I will have more, I'll add games, etc. All pretty much for free (I did spent about 100 usd on the facebook-type-of-social network). How: joomla. Open source, loads of plugins. 100s of thousands of developer's work, designers work, testers, etc. I would never be able to do this myself, neither would I be able to pay for ever. But it's for free, so I didn't need to. And by the way: joomla is only one of many open source cms.

What I can't find is a proper web-based email client which is "sexy", and which integrates properly within the cms system. I found and bought a roundcube wrapper, to plug in into my wonderful website. But unfortunatly this very-old-looking-crap-email webclient is just not right. It's slow, the interaction is silly, you need to buy expensive templates to make it work with mobile devices. It just does't fit in. It looks old.

Joomla comes with a lot of free stuff, plugins, authentication, address books, multi language, templates, mobile devices support, ALL you need for a proper website. Just needs a bit of effort to glue it all together (no software development).

Now I will work on a plugin to interact with my mail server, then I have this done in no time.

Don't re-invent, but don't get depressed neither.