如何使用 PHP 构建基于 Web 的电子邮件客户端?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1092723/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 00:55:40  来源:igfitidea点击:

How do you build a web based email client using PHP?

phpemail-client

提问by panidarapu

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

我想学习如何用 PHP 构建一个基于 web 的电子邮件客户端(类似于 yahoo 和 gmail)。

Does anyone know how I can get started with this?

有谁知道我该如何开始?

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

我希望我的系统能够发送和接收电子邮件。

回答by Pascal MARTIN

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).

最明显的答案是“不要”:已经有很多网络邮件软件,其中一些是基于 PHP 的(例如,如果您依赖于使用 PHP,因为您已经拥有基于 LAMP 堆栈的服务器)

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

只引用几个名字,都是基于 PHP 的,你可以看看这些:

  • 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...
  • SquirrelMail:一个很老的,不是很性感......但多年来一直在做这项工作
  • Horde IMP: 也是众所周知的,而且相当强大
  • roundcube:可能是我尝试过的列表中最“性感”和“web 2.0”的
  • AtMail:我从来没有用过这个,所以我不能说更多......

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

我已经使用列表中的三个第一很长一段时间了;roundcube 绝对是最“用户友好”的,我想说......

(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 toset up a Webmail, say, for you company : definitly use some already existing software:

现在,如果您必须为您的公司设置 Webmail:绝对使用一些现有的软件

  • 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 ^^)
  • 现有的软件已经相当“”了:
    • 很多人使用它,这意味着很多人说“这可以做得更好”,或者“这对用户不友好”,或者……你明白了;所有这些都使现有软件变得更好:-)
    • 许多人会试图破坏这样的应用程序——这意味着大量的安全修复,这意味着一个应用程序可能比你在很长一段时间内编写的更安全......
  • 一个现有的开源应用程序将代表数百天的工作
    • 你真的准备好花那么多时间在已经存在的东西上工作了吗?
    • 如果你在一家公司工作:你的公司准备好支付你一年的工资了吗?甚至可能更多?正在研究已经存在的东西?
    • 你不相信我吗?阅读这篇博文:代码:微不足道;这是关于stackoverflow的,但对于网络邮件软件来说完全相同(除了stackoverflow是最近的——并且可能有更少的代码贡献者;但这只是一个疯狂的猜测^^

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

作为旁注:如果您的公司希望您构建一个 gmail 的克隆,您不会(同样的事情:有多少人在 gmail 上工作?您的公司有多少程序员?您的公司可以在这方面花多少钱?)。 ..
每年只需几美元,您的公司就可以为每个员工拥有一个“专业”的 Google 帐户,顺便说一句...



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 :

毕竟,如果您仍然想/必须使用 LA*(M)*P 堆栈编写自定义的手工网络邮件,您至少需要了解以下内容:

  • 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...
  • 如何在 PHP 中编程
  • IMAP 的基础知识(即使你使用库/框架,这么大的应用程序也需要你了解底层协议的一些东西,或者永远不会理解“为什么”或“如何”出错)
  • HTML / CSS / Javascript (有一些 AJax 知识——来吧,现在是 2009 年!)
  • 因此您的应用程序更易于维护(并且可以添加/返工/修改内容并纠正错误),您可能需要使用一些框架,并遵循一些设计模式和最佳实践

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.

考虑到所有这些都不是问题(如果您已经不太擅长这一切,和/或没有太多经验,可能至少需要几年时间才能获得...考虑编程和网络开发是您的全职活动),您可以开始考虑使用例如 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 urgentfor 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 !
  • 错误报告;对于用户来说,这些几乎总是很紧急的——比如“天哪,我不明白什么都不起作用了,我现在必须收到我的邮件!
  • 对进化的要求:用户总是想要更多的东西,比如“我在我的个人帐户的 gmail 中看到了这个;我们的公司帐户怎么没有呢?这是我们用来工作的工具!
  • 这太慢了,我无法工作!”; 然后,祈祷您在设计/开发应用程序时考虑了可扩展性和优化!

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 !


不管怎样,祝你好运!和/或玩得开心!

回答by Paul Grigoruta

  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
  1. 学习网络堆栈:HTML、javascript、php、mysql...
  2. 写几个小项目
  3. 在某个地方受雇向更有经验的人学习
  4. 学习 OOP、设计模式、最佳实践等
  5. 应用你几年学到的东西

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

如果你通过了第 5 点,你就会知道如何构建一个。

回答by Greg

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

您可以使用 PHP IMAP函数轻松构建一个简单的函数,但如果您必须提出要求,那么它对您来说可能有点复杂。

Have you considered using a pre-built one:

您是否考虑过使用预先构建的:

回答by Dave Archer

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

您的主要选择是
1. 直接将您的代码与现有邮件服务器集成
2. 使用 IMAP 和 SMTP 与现有邮件服务器通信

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

第 2 条是最直接的,因为您可以在需要时更改邮件服务器。

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

是的,还有很多事情需要考虑

回答by pbreitenbach

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).

设置可通过 POP 访问的电子邮件帐户(例如:gmail)。然后使用 PHP IMAP 函数通过 POP 协议(​​POP 可能比 IMAP 更容易)(http://us2.php.net/imap)检索电子邮件。要发送邮件,请使用 PHP 邮件函数 ( http://us2.php.net/mail)。

回答by DLH

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 tutorialfor 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.

如果您不使用外部邮件服务(如 Gmail),则需要配置自己的服务器来存储和发送电子邮件。这是使用 Postfix(用于发送邮件)和 Dovecot(用于通过 IMAP 访问邮件)的教程。本教程还介绍了在 SquirrelMail 中设置网络邮件系统。您可以这样做,或者,如果您真的想开发自己的系统,您可以编写一个 PHP 应用程序来访问您的邮件。

Good Luck!

祝你好运!

回答by Jo Witters

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.

我同意。对于目前我们所坚持的所谓最性感的界面,很明显我们需要一些不同的东西。对于那些认为我喜欢发明轮子的人:我不!我刚刚安装了一个新网站,我对结果非常满意。我基本上使用了 1000 个小时的免费开发人员的工作,并且不愿意重新发明以前做过的东西,要好 1000 倍。我会用我现在拥有的 10% 来设计一个网站,并且会花费 10 倍的时间。布局很棒,功能很棒。我有身份验证、脸书类型的社交网络、供我和我家人存储文件的私人区域、议程、照片和视频支持、youtube 集成、facebook 集成……我会有更多,我会添加游戏, 等等。几乎都是免费的(我确实在 facebook-type-of-social 网络上花了大约 100 美元)。如何:joomla。开源,大量插件。数以千计的开发人员的工作、设计师的工作、测试人员等。我自己永远无法做到这一点,我也无法永远支付。但它是免费的,所以我不需要。顺便说一句:joomla 只是众多开源 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.

我找不到合适的基于 web 的电子邮件客户端,它是“性感的”,并且在 cms 系统中正确集成。我找到并买了一个圆形包装纸,插入我的精彩网站。但不幸的是,这个看起来很老的垃圾电子邮件网络客户端是不对的。它很慢,交互很愚蠢,您需要购买昂贵的模板才能使其与移动设备配合使用。它只是不适合。它看起来很旧。

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).

Joomla 带有很多免费的东西、插件、身份验证、地址簿、多语言、模板、移动设备支持,所有你需要一个合适的网站。只需要一点点努力将它们粘合在一起(无需软件开发)。

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.

不要重新发明,但也不要沮丧。