How to make a PHP script that reads an email from the server?

is there any way when the user sends an email to the address admin@xx.com , php script automatically reads the email information and plays it automatically?

EDIT :: is there any method when someone sends me an email at admin@xx.xx script will be called, which is better than using the cron job every 5 seconds

Greetings

+4
source share
2 answers

As already mentioned, checking mailbox (POP3 or IMAP) is a valid way to handle email. However, if you are looking for real-time processing, it is really possible that mail is delivered directly to php as standard input.

Basically you tell the mail server to deliver the message to a local script.

You will need to delve into the CLI PHP and set up your mail server (which should be on the same server as when processing the script). So this is not an easy process. But it is possible. Using this method, I am currently running a discussion list via email based on PHP.

I set up my old time, so I can’t remember all the details; but this article should point you in the right direction.

+3
source

Take a look at the php imap extension module . It can access pop3 and imap accounts.

If and how you can run the script when the email is delivered to the inbox depends on your local mail system. For instance. with qmail you can use the command line in .qmail . You can ask ServerFault how it works and how it is configured (and where: afaik.qmail is not the only place you can add the line command).

0
source

Source: https://habr.com/ru/post/1304673/


All Articles