Reputation: 1810
I know you can send emails with PHP but, can you receive emails through PHP?
Upvotes: 26
Views: 34767
Reputation: 1
As mentioned PHP has traditional functions for IMAP and NNTP, but I do suggest using a simpler solution like using some external service that can provide attaching a custom domain and create email addresses to receive emails to. This is of course if you don't need to grab emails from providers such as Gmail, ProtonMail, etc.
I would suggest you to learn the following article about https://proxiedmail.com:
https://dev.to/yatsenkolesh/how-to-receive-email-with-php-3k21
We have a good PHP client with Laravel support that allows you to receive emails to your application via webhook or just by browsing the received emails list.
Please note that I'm a founder of the service and also it's paid, but email webhook is free for up to 200 received emails/day (then 9 USD/year).
Upvotes: 0
Reputation: 86805
You can pipe incoming mails into a PHP script so you can process it directly. Evolt has an article on how to setup something like that. This can be useful if you want to activate scripts programmatically by sending Emails to it (like responses to a newsletter mail that unsubscribes the user).
If you just want to read mails using PHP, PHP has native functions to talk to IMAP, NNTP and POP mailboxes.
Upvotes: 19
Reputation: 74252
Only a mail server can receive e-mails. You could read mail box formats (such as mbox or Maildir) to read e-mail using PHP.
PHP scripts functioning as IMAP/POP3 servers can receive e-mail sent to them.
Upvotes: -2
Reputation: 522175
You could write a mail server in PHP that binds to a port and listens for incoming email.
But PHP is not the language I would recommend for tasks like this, and it would also be a hugely complex undertaking.
You can hook into an existing mail server as callback script, or periodically query a mail server via POP or IMAP. The latter option is the most common: run a PHP script that processes an email account via a cron task in intervals. See http://php.net/imap.
Upvotes: 3