Jump to content

How to make a server run a script when an email arrives?


tcjohans

Recommended Posts

Hi!

 

I want to build a PHP-based mailing list manager.

The problem is how to handle processes initiated by emails, say if a person sends an email from his/her regular email program or webmail site (hotmail, aol, pandora, whatever), e.g. to send an email message to a list he/she is subscribed to or to send an email for automatic unsubscription (with "unsubscribe" in the subject line) from a list, etc.

 

How would the manager handle such a process? Is there a way to get a server to automatically run a PHP script whenever, say, an email comes in addressed to some email address at @lists.MYDOMAIN.org

(say if the email is addressed to [email protected])?

 

Or could I solve the problem by using some other scripting language, say, Perl or Python (which I don't know too well currently)?

 

Thomas

 

Actually, I can tell this much about my server so far (maybe this gives some indication of the mail server??):

 

Apache version 1.3.37 (Unix)

PHP version 5.2.4

MySQL version 5.0.27-standard

Architecture i686

Operating system Linux

Path to sendmail /usr/sbin/sendmail

Path to PERL /usr/bin/perl

Kernel version 2.6.18-8.1.8.el5

 

A workaround would involve using cURL to open your webmail client and then taking that page's data and extracting it and using it as you needed, but I don't know what details you are looking.  You might want to look into the PEAR extension as it does a lot with mail and might be able to help you.

A workaround would involve using cURL to open your webmail client and then taking that page's data and extracting it and using it as you needed, but I don't know what details you are looking.  You might want to look into the PEAR extension as it does a lot with mail and might be able to help you.

 

I am not sure I understand what you mean here. What I need is a way to get a php script to run when an email comes in to the mail server posted to an email address that ends with "@lists.MYDOMAIN.org" - the php script would process it, e.g. if it is addressed to a mailing list it would check the MySQL mailing list database for a list of all subscribers to the list in question and then mail it off to them.

 

Alternatively, an idea that came to my head today: If the mail server can just make sure to store/save all such incoming mail for some reasonable amount of time - without responding or reacting to them in any particular way -, then I should be able set up a cron job that executes a php file regularly to check all such incoming mail and performing the appropriate processes for each (e.g. forwarding to the appropriate mailing list, unsubscibe the email address, subscribe the email address, etc.)

 

But I don't know anything about mail servers at this stage. Does any of these solutions make sense and be feasible?

 

Or how do other script-based mailing list managers handle this particular problem - i.e. how to handle incoming mail?

 

Thomas

 

 

A solution that somebody proposed on another site is just to open a mailbox - pr one for each mailing list - on the mailserver, get incoming mail directed to these, and then use cron to set a php to process them regularly at short intervals.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.