开发者

How do I update a blog by sending an email, using php

开发者 https://www.devze.com 2022-12-29 17:57 出处:网络
I want to update a blog, by sending an email using php.This is not wordpress, tumblr, or the famous开发者_如何学JAVA ones.

I want to update a blog, by sending an email using php. This is not wordpress, tumblr, or the famous开发者_如何学JAVA ones.

I could set up an email id, with a specific code in the subject line, but how I get input the contents into the db?

Thanks Jean


You could set up a cronjob starting every x minutes and checking for new mail. Use the PHP imap-functions to retrieve and parse the mail and then dump the contents into your database.

http://php.net/manual/de/book.imap.php


As others have suggested you could poll a mailbox to detect an incoming message - but its far more efficient to get the MDA (mail delivery agent) to trigger the process when a mesage arrives - how you do this depends on how your mail system is configured (on most Linux systems procmail is used for the MDA which provides all sorts of filtering, automatic responses and execution functionality, failing that, .forward files in the users home dir can usually do at least part of the job).

In terms of parsing the message - it should contain one or more headers seperated by a newline (or carriage return + newline) followed by at least one blank line, followed by the body. But you'll need to think about how you deal with mime encoded content.

Regardless of how you get the email you still need to get it into the blog.

Most blog software supports some form of xmlrpc for adding messages - there's a lib published at http://phpxmlrpc.sourceforge.net/

Have a look at the discussion pages for examples of usage as a client.

Failing that - try reverse engineering the form used to submit a new post.

C.


You probably need to do socket programming to listen to the email incoming port and whenever you receive an email via the port (make sure you comply with the correct protocols on the higher layers) , you can take in the body and subject and post it into your blog's database.

You will need to keep the script running in a loop. However, this kind of task are usually not done on a platform like PHP. You can do console based applications to run on your server on C or C++ to perform such tasks as they are more suitable.

Dedicate PHP to serve the front end of your website/server.


You can use a job scheduler like cron to periodically check for new emails and update the database.

Or use a web service like webcron http://www.webcron.org/ to launch your script, similar to cron.


You'll have to use PHP to routinely check the email account via something like POP3. This blog post talks about doing exactly this

0

精彩评论

暂无评论...
验证码 换一张
取 消