PHP Perform Action with Incoming Email

冷暖自知 提交于 2019-11-29 08:56:19

If you use cpanel you can pipe the email to a script which then processes the email accordingly. You can find that option under the email forwarders.

You want to use cron. It's the standard Unix way of running scripts on a regular basis without any user intervention. Create your script, make sure it can be run by the server user, then schedule it (the full command, e.g., php myscript.php in cron). It won't run when an email is received, but you can run the script often enough that the difference won't be noticeable.

If you are running the website on a UNIX server you have access to you can do this with procmail, sieve or similar mailtransport helpers. You would have to create a useraccount for the alias recepient as procmail is only invoked to process "real" users mail. Your .procmailrc would look something like this:

:0
*
| /usr/bin/php /path/to/your/script.php

And remember that procmail will pass it's info as arguments (and in the env variables).

The above scenario might not at all be possible for you, but if it is then I recommend taking a closer look at http://www.procmail.org/

Alternatively, you may be able to "pipe" the email directly to your PHP script. The process to do so will slightly differ depending on your email suite and/or server control panel software. You may be able to get "inspiration" from the Kayako manual at http://www.kayako.com/manuals/Kayako_SupportSuite_User_Manual_PDF.pdf (page 61 onwards) which shows how to setup email piping to the Kayako support helpdesk. You'll have to write the PHP file which reads in the file from STDIN yourself though.

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