如何创建邮件服务器?
我想要一个能够接收电子邮件的服务器。然后我想使用 PHP 来编程向用户显示电子邮件的方式。我可以纯粹用 PHP 来做吗?我的意思是,从PHP发送电子邮件没有问题,但我不知道我是否可以通过PHP接收电子邮件? (在某种程度上 PHP 接收 POST 请求)。
添加
作为对第一个答案的回应,我想指出我似乎需要一个 SMTP 服务器。我希望能够以编程方式与 SMTP 服务器进行通信。例如,我希望能够“告诉”SMTP 服务器创建一个新的电子邮件地址。我还需要知道传入电子邮件的存储位置以及格式。例如,我如何从与收到的邮件对应的文件中提取“发件人”、“抄送”、“密件抄送”。
I would like to have a server that is able to receive emails. Then I want to use PHP to program the way the emails are shown to the users. Can I do it purely with PHP? I mean, it is not a problem to send emails from PHP but I do not know if I can receive emails by PHP? (In a way PHP receives POST requests).
ADDED
As a response to the first answer, I would like to specify that it looks like I need an SMTP server. I want to be able to communicate with the SMTP server in a programmatic way. For example, I want to have a possibility to "tell" to the SMTP server to create a new e-mail address. I also need to know where incoming emails stored and in what format. For example, how I can extract the "sender", "cc", "bcc" from the file corresponding to the received mail.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您从头开始编写它,那么您将需要SMTP 规范。我强烈建议不要这样做。 SMTP 服务器很难编写,并且有几个非常好的开源解决方案。
我对 PHP 的理解是,它在多线程方面表现很差,所以它可能不是解决这个问题的好方法。
接收邮件的服务器通常不会向用户显示邮件。他们通常以其他软件(例如本地电子邮件客户端或 IMAP 服务器)访问的标准方式(例如 Maildir 或 mbox)存储它们。
向用户显示电子邮件的工作属于电子邮件客户端。基于Web的PHP网络邮件软件包括SquirrelMail和RoundCube。 AFAIK 他们都充当 IMAP 客户端。请参阅 IMAP 规范。
选择在您的操作系统上运行的 SMTP 服务器。阅读说明以了解如何配置递送和接受地址。它通常归结为操作文本文件。
再次。请参阅邮件服务器手册。大多数都会为您提供有关存储数据的位置和格式的选项。
然后您只需要决定是让 PHP 直接深入研究这些内容,还是使用 IMAP 服务器。
If you are writing it from scratch then you'll need the specification for SMTP. I would advise very strongly against this. SMTP servers are hard to write, and there are several really good open source solutions out there.
My understanding of PHP is that it does very poorly when it comes to multithreading, so it probably isn't a good solution for this problem.
Servers that receive mails do not typically show them to users. They usually store them in a standard way (such as Maildir or mbox) which other software (such as a local email client or an IMAP server) accesses.
The job of showing email to a user is belongs to email clients. Web based PHP web mail software includes SquirrelMail and RoundCube. AFAIK they both act as IMAP clients. See the IMAP specification.
Pick an SMTP server that runs on your OS. Read the instructions to find out how to configure delivery and accepted addresses. It usually comes down to manipulating text files.
Again. See the manual for the mailserver. Most will give you options about where to store the data and in what format.
Then you just need to decide if you are going to get PHP to dig into those directly, or use an IMAP server in between.
不,这不容易实现。 PHP 是为(无状态)http 协议而设计的,而邮件是在由各种请求和响应构建的对话中发送的。
可以使用 PHP 解析和处理邮件,但我建议安装一个可以使用 POP3 从 PHP 读取的邮箱。然后,您的 PHP 应用程序可以显示并处理来自该邮箱的邮件。
No, that is not easily possible. PHP is made for (stateless) http protocol, while a mail is sent in a conversation that is built up from various requests and responses.
It is possible to parse and process mails using PHP, but I would recommend installing a mailbox that you can read from PHP using POP3. Then, your PHP application can show and process mails from that mailbox.