简体   繁体   English

如何使用php脚本获取消息?

[英]how can I fetch a message using a php script?

I want to make it so that I can email a url and a php script or something at that url will take the contents I emailed such as message body and write them into a DB. 我想这样做,以便我可以通过电子邮件发送url和php脚本,或者该URL上的内容将接收我通过电子邮件发送的内容(例如消息正文)并将其写入数据库。 I know how to write something into a DB but I dont know what to do in order to EMAIL to a url or person and have it pull out the message. 我知道如何向DB中写入内容,但是我不知道该如何做才能通过电子邮件发送给url或人员并让其提取消息。

The reason I am thinking of emailing to a url if possible is because this saves me the massive blob of trouble of setting up IMAP and using all that mess. 我考虑尽可能通过电子邮件发送到url的原因是因为这免除了设置IMAP和使用所有混乱的麻烦。 I know this can easily be done with php I just have no idea how. 我知道这可以很容易地用php完成,我只是不知道怎么做。

You cannot send email to a URL, you must use a valid email address. 您无法将电子邮件发送到URL,必须使用有效的电子邮件地址。

If you want to read your email from within php to import into a DB, you'll need to communicate to your IMAP/SMTP/POP3 server via a socket connection with the fsockopen() function. 如果要从php中读取电子邮件以导入数据库,则需要通过套接字连接使用fsockopen()函数与IMAP / SMTP / POP3服务器通信。

I suggest you download any open source web based mail client such as RoundCube , Squirrel Mail , etc... and examine the source code. 我建议您下载任何基于Web的开源Web邮件客户端,例如RoundCubeSquirrel Mail等,并检查源代码。

There are quite a lot of options when it comes to receiving email. 接收电子邮件有很多选择。 You'll still need to use an email address to send to but you can forward that email on via an HTTP POST using a couple of options such as cURL scripts or using a third party like CloudMailin . 您仍然需要使用电子邮件地址进行发送,但是您可以使用cURL脚本或CloudMailin之类的第三方选项,通过HTTP POST转发该电子邮件。

I wrote a blog post about this in Rails (although the principles apply directly to PHP too without much modification. This is a dup of a couple of other questions but it was asked in a fairly different way hence the answer. 我在Rails中写了一篇关于此的博客文章 (尽管这些原理也无需修改就可以直接应用于PHP。这是其他几个问题的重复,但提出的方式却完全不同,因此得出了答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM