M
M
mitaichik2015-04-20 19:47:12
PHP
mitaichik, 2015-04-20 19:47:12

How to receive emails in php?

Hello everyone) You need to create a mail server in which you can programmatically create accounts (mailboxes) from php, receive letters on them and parse them.
And so that you can set up a hook - when a letter arrives, a script would be called.
How to do this? In which direction to dig? Server on ubuntu.

Answer the question

In order to leave comments, you need to log in

5 answer(s)
S
SagePtr, 2015-04-20
@SagePtr

Well, in PHP, starting from some version, you can create sockets and listen for incoming connections, so you can write your own mail server that accepts letters and allows you to check) Another thing - is it necessary?)

O
OnYourLips, 2015-04-20
@OnYourLips

And so that you can set up a hook - when a letter arrives, a script would be called.
Read the documentation for services that provide such services.
In the general case, this cannot be done. Only in private.

P
Pavel K, 2015-04-20
@PavelK

Isn't it easier to use VPS and raise your mail server?
Boxes can be stored in the database and created accordingly from php
. Letters themselves can also be stored in the database, and run a php script by cron and make the necessary selection even by regexp.
Postfix + dbmail will handle this.

N
Nazar Mokrinsky, 2015-04-21
@nazarpc

Set up a mail server, in the settings of the mail server you make a command call upon the arrival of a letter (how exactly it depends on the server used, this is another question). And what kind of command it will be - it's up to you to decide whether you make a call to the php file if necessary, or an HTTP request somewhere, or something else.
Look at iRedMail, after installation you have a mail server, a database with accounts, letters in some format in the Dovecot file system stores (google in which one if necessary, I don’t remember offhand, I’m too lazy to search). It remains to dig into the graphic panel to figure out how to create arbitrary accounts yourself directly and pull out what you need.
Thus you have:

  • Mail server with database
  • Calling a script upon receipt of a letter
  • In the script, go to the folder with letters and pull out everything you need
  • If necessary, change the records in the database to add domains and accounts, manage quotas and all that

A
Alexander Kubintsev, 2015-04-21
@akubintsev

The task is not completely clear. Why do you need to create mailboxes and parse letters from there? If this is not a service for people, but you just need to make dummy boxes, then it's easier to set up an email alias system so that letters actually fall into one real box.
Or even set up a mail server so that all letters to non-existent emails in the domain fall where you need.
I think it will be easier to implement than what you originally intended.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question