How to implement a feature: Post to a forum via email?

雨燕双飞 提交于 2019-12-06 15:12:54

Setting up a script triggered by receipt of email to a particular address would be the simplest. That way you don't need to write a new cron script. You would want to create a special email address dedicated to receiving such emails. The thread could be identified by something in the subject that would be required. I'm not sure of your use case so that's the best I can suggest. And you could also require the email to contain something to identify the sender as one of your authenticated forum members. You might need to expose a secret token to them or something. That way if any spammy stuff gets in you can block the account of whoever is sending it.

I believe some opensource forum software has this built in, or has an add on you can install to do it. Even though you're doing your own, you might like to get these modules to see how they do it.

You can create a sceduled (crontab, windows scheduler) script which does the job (reads all the incoming files from SMTP drop folder and posts the messages). However, two questions arise:

  • how will you know which thread to post to?
  • how will you filter spam messages?

PHP has IMAP functions that can read POP3 mailboxes. You would want to combine those with a cron job for frequent polling.

Some mail servers also offer triggers to run when mail comes in - you could create a trigger that calls a PHP script, passing on all the details of the incoming message. If you have access to your server and can implement this, it might be easier to work with because you don't have to connect to the POP mailbox yourself in your script.

If you have a POP3 mail box with good spam checking, this might work - although you would, as Naivists says, of course have to find a method how to identify the target thread reliably.

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