MTA for receiving mails, in PHP

女生的网名这么多〃 提交于 2019-12-10 12:16:47

问题


is there a library/class/code-snippet/etc. that allows me to directly receive mail in php?

So that I don't have to run an additional sever in an other process and then have to somehow send the mails to the already-running php-process.

I've been looking around for a while, but results for "php" and "mail" or "mta"/"smtp" on google focus mostly on sending mail, or retrieving it using pop3 or imap...

[EDIT]

What I'm trying to do is forward the messages to an IRC-channel, so obviously when the IRC-bot (in PHP) isn't running, loosing the mails is not a big deal. However having a low latency between receiving the mail and posting it on IRC is.


回答1:


Writing your own SMTP server to act as a MTA is a big undertaking. You could take a look at http://cloudmailin.com. CloudMailin allows you to receive the incoming email as an HTTP Post and acts as the MTA sending the email direct to your PHP app. The PHP app can then process the email and send it to the IRC channel.




回答2:


I've never seen a compete SMTP server in PHP and it doesn't surprise me. I don't think you want to go that route. I can think of two other ways to do this:

  1. Use procmail (or similar) with your existing SMTP server and make a rule that forwards the messages to your PHP script. Pretty simple to do and it will fire the script the instant the message is received.

  2. Have the messages delivered to some existing mailbox, then have your PHP script continually poll it (via POP or IMAP) for new messages. When you see a new message, pass it to IRC and delete it. How long it takes the message to appear depends on how often you poll the inbox.




回答3:


Writing your own SMTP server is a huge undertaking. Do NOT go this route. You'll waste an incredible amount of time duplicating work that's been done already. Choose one of the 'big' SMTP servers (postfix, exim, sendmail, etc...) and go with that.

Don't think that just setting up a dinky little script to listen to port 25 will do the trick. SMTP servers are incredibly complicated beasts and the mechanics of setting up that port 25 socket likely occupy less than 0.00000000000000000000000000000000001% of the work. (this number is totally true, I asked my gut what it feels and that's what came out).




回答4:


Try this: http://www.php.net/manual/en/refs.remote.mail.php

10 seconds of googling. SMTP is for mail relay, although it is the defacto protocol for mail clients to send mail, due to the Unix heritage of every box running an SMTP mail relay.

POP3 and IMAP provide mail clients' access to mail.




回答5:


The MTA (Mail Transport Agent) is an application (i.e. sendmail, exim) that is used to move mail from location to location. As far as I know, there is no MTA coded in PHP. PHP offers classes and scripting that will handle mail transport, but it still processes through an existing MTA.

You should be able to configure the MTA to pass mail through a given PHP script to accomplish what you are looking for.



来源:https://stackoverflow.com/questions/5861389/mta-for-receiving-mails-in-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!