Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you receive emails through PHP?

Tags:

I know you can send emails with PHP but, can you receive emails through PHP?

like image 434
Steven Hammons Avatar asked Mar 02 '11 02:03

Steven Hammons


People also ask

How does PHP email work?

PHP mail is the built in PHP function that is used to send emails from PHP scripts. It's a cost effective way of notifying users on important events. Let users contact you via email by providing a contact us form on the website that emails the provided content. You can use it to email your newsletter subscribers.

Does PHP mail need a server?

Php uses by default, the local mail-server. However you can specify this in your php. ini configuration file.

How can I retrieve mail from Gmail using PHP?

php /* connect to gmail */ $hostname = '{imap.gmail.com:993/imap/ssl}INBOX'; $username = 'my gmail id'; $password = 'my gmail password'; /* try to connect */ $inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' .

What is PHP mail and SMTP?

Overview. When you use the PHP mail function, you are sending email directly from your web server. This can cause issues if the FROM address isn't set properly or if your email isn't hosted with DreamHost. Sending mail via SMTP is recommended as email is sent from the mail server rather than the web server.


2 Answers

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.

like image 94
Eran Galperin Avatar answered Oct 26 '22 17:10

Eran Galperin


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.

like image 25
deceze Avatar answered Oct 26 '22 16:10

deceze