ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: Ubuntu 7.04, Experimenting with others
Posts: 46
Rep:
Receiving Emails through web server? (PHP)
I'm looking for a way to "intercept" emails sent to my server...I'm not sure quite how to describe what I'm looking for. Basically, I'm working in PHP, and I want to create a completely web-based e-mail service. This means that I don't want to use some sort of "external" servers and such.
I need to figure out how, when people send e-mails from their client to an address on my server (aka someone@mysite.com), I want my webserver (meaning a script on that server) to catch that request so I can deal with it.
Oh, and I'd like it to be cross-platform. (Honestly, I want it to all work in PHP).
Can anyone give me a little help here? I don't know anything about email, that's my biggest problem; once I get the e-mails, I can deal with it all from there Even just something on basic email theory would help - it doesn't have to be PHP related (that's why I'm posting it here, rather than a PHP-centric forum).
Did I read this right? You want to create an entire mail server setup in PHP? Including receiving emails and so forth?
It could theoretically be done, although you'd have to write external applications in PHP and set them up to answer on the right ports.
The most important question is how do you receive your email now? Do you use fetchmail to get it from your ISP, or is your machine the MX for your domain?
I think it would be better to set up an external mail-fetching-and-storing system, and just use PHP to talk to that with the IMAP module. If you go about trying to re-create SMTP, POP3 and IMAP protocol handlers (not to mention implementing RFC822 and friends), you're going to be fixing it for the rest of your life.
Distribution: Ubuntu 7.04, Experimenting with others
Posts: 46
Original Poster
Rep:
Hmm, well, that's pretty close to what I want. I wouldn't necessarily consider it a "server", but a whole email "application".
I'm not looking to do this to "replace" anything I have now, I'm basically wanting to do it just to see if it can be done.
I'm hoping to find a way to setup a completely POP3/IMAP-free (and possibly SMTP-free, depending on how PHP handles it) email solution, similar to how Yahoo! Mail or Hotmail works.
Well, I know nothing about e-mail, or basically any forms of server communications. Basically, the most important thing I need to know is how the server knows it's getting an email and all that, so I can see about grabbing that and using it how I need.
I know I sound like a , and in the case of server communications, I guess I am.
That's ok then What you want to look at is the IMAP module of PHP (which, confusingly, also handles POP3 through functions named imap_*). Also, the mail module handles sending email outwards. The mailparse module also has some useful functions for interpreting what the server will give you.
I would recommend setting up an IMAP server to talk to, as this gives you more flexibility for things like searching through email, creating folders, and also handles the storage side of things nicely. Also, for hints and tips, you might like to install one of the existing PHP mail systems. If you have some more specific questions about email, post them here
Distribution: Ubuntu 7.04, Experimenting with others
Posts: 46
Original Poster
Rep:
Oops, I think I said something wrong. I'm looking to avoid routing it through an IMAP or POP3 server. I'm not really looking to setup an "email server", I'm looking for a way to avoid one altogether (Although I suppose it could be considered a server...).
Basically, I'm hoping to develop a standalone webmail service, that doesn't need anything externally. All I really need to figure out is how to "grab" the emails when they're sent to my domain, basically reroute them to the Web server so I can have my script interpret them and put the info into a database.
Is this even possible? That's the big question. If someone can point me at something about how emails work, how the server knows when it's got an email, etc, that would be perfect (is it by port, or protocol, or what?)
I guess this is all really confusing, and honestly I'm not exactly sure what I want, muchless how to convey it...basically, I want to setup a script on the web server to read emails....I might have to actually build a simple mail server to redirect, but I'm hoping it won't come to that; ideally, I want it all in PHP.
OK, we're back to how you currently get your email. There are two methods for this - one is direct SMTP, where you have your server set up to receive SMTP directly from the net (it is one of the MXs for a domain name, or your ISP handles it and passes on everything via SMTP to you). For this, you will need an SMTP server. The other way you might get your mail is have your ISP receive it as the domain's MX, and you pick it up via POP3 or IMAP. Mail is usually delivered locally on your system by a program like sendmail, qmail, postfix or courier, and usually does this via SMTP (albeit internally). For example, fetchmail grabs email via POP3 according to your configuration, and then 'sends' it to port 25 on your local system. In order for your system to get email, you are going to have to speak at least one of POP3, IMAP or SMTP. Otherwise, you need to let other programs handle it, and read the email files from a user's mail store.
So realistically, I think you are going to have to build a working mail server. You might be able to get away without a fully functional one, but how you go about that is determined by how you get your mail now (and whether you want to support other configurations later). By writing a PHP mail client instead, you get all the functionality you will need to read and write emails, but without all the hassle of learning too much about email. Is there something you need to do that can't be done with existing mail server software?
Distribution: Ubuntu 7.04, Experimenting with others
Posts: 46
Original Poster
Rep:
Hmm, I was afraid of that. I suppose my idea was a bit out there, oh well. Thanks for your help, though...I might build this at some point, but considering I would have to venture outside of PHP, I'm not so sure I want to do it.
Hmm, I could always do it to work with another server, but I dunno. Thanks for the assistance, though.
Distribution: Ubuntu 7.04, Experimenting with others
Posts: 46
Original Poster
Rep:
Well, it might be useful along the line, but the first thing I'd need to do would be to find out how to get the mail...which seems impossible, in PHP at least.
It's not impossible in PHP. It's possible to:
a) Get your mail via POP3 if your ISP provides it to you this way. For example, my ISP sends all email for my domain to a single POP box, and I use fetchmail and postfix to send it to various user accounts. I could replace fetchmail and the mail storage side with a web-based interface (though it would be more awkward to convince a PHP script to run periodically).
b) Write an SMTP server in PHP, but it would not run via Apache - i.e you would have to build the program standalone (and spend the rest of your life solving problems that others have solved many times).
I honestly don't understand the point of replacing a fully functional mail system with a slower version written in PHP.
Distribution: Ubuntu 7.04, Experimenting with others
Posts: 46
Original Poster
Rep:
Well, see, I'm looking for a way entirely in PHP...no rerouting, no standalone programs...just PHP scripts. That may not be impossible, but it seems to be close.
Quote:
Originally posted by CroMagnon I honestly don't understand the point of replacing a fully functional mail system with a slower version written in PHP.
Cuz I can. (Well, no, I guess I can't...) Honestly, I figured it might be a nice idea to see if there was a way. Heck, it might be a bit slower, but the point is it's all web based; it would let people just drop in an email system for their sites...no extra programs, no special access, just a script.
alot of places do this already a few free web based email places allow you to check a POP account also and sending mail though it is simply a matter of using that address as the reply-to.
Originally posted by gothgeek84 Well, see, I'm looking for a way entirely in PHP...no rerouting, no standalone programs...just PHP scripts. That may not be impossible, but it seems to be close.
Cuz I can. (Well, no, I guess I can't...) Honestly, I figured it might be a nice idea to see if there was a way. Heck, it might be a bit slower, but the point is it's all web based; it would let people just drop in an email system for their sites...no extra programs, no special access, just a script.
There is a way to send mail from php. Click on any user here from the profile you can send them mail. But ofcoz they cant read it in here since it goes to their "mail box".
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.