 |
| Coding Forum Problems with your code? Discuss coding issues, including JavaScript, PHP & MySQL, HTML & CSS, Flash & ActionScript, and more. |
|
 |
11-06-2008, 08:01 AM
|
#1 (permalink)
|
|
Junior Member
Join Date: 11-06-08
Posts: 6
Latest Blog: None
|
How do push emails to PHP via Sendmail
Hi Guys,
Right let me explain my situation, about 4 years ago I worked on a booking system for an entertainment agency, now recently they have been giving each agency their own email address and each broker within that agency also has their own email.
Now this all works fine, but recently ive been drafted back in again to apply some changes and updates to the system to bring some extra features and technology, one of the features they have come up with is the ability to 'file' incoming emails against a contact on their database ...
So, heres the plan
1. Use a catch all type system and push any incoming email to PHP
2. Use PHP to save emails into the database where the username match's
3. Return error on any unmatched user
4. Delete email (if needed!)
Now originally we thought of getting PHP to check a pop3 mailbox every xx seconds etc, but then decided this wouldnt be accurate, it would require a LOT of connections and cause some performance problems. The next problem was that the agencies and brokers are changing daily, hence keeping track with pop3 mailbox's would be crazy, we are talking approx 14,000 users each with their own email.
So its been suggested about getting Sendmail to pipe data into a PHP CGI script so its inserted direct to a MySQL backend, from there the normal system can then use this data as it sees fit ... However, Ive never done this before ... does anyone have any clues as to ways about this? best practices? sample code ...
Really looking for a starting point on this one, tbh what we are really looking at is a webmail system where the mail is stored on a MySQL database as soon as its recieved.
I look forward to the debate and replies to come, I hope someone can help.
Thanks
Mike
Btw, the server is a linux based with PHP 5.2.6, cPanel and the latest stable release of sendmail.
|
|
|
11-06-2008, 09:24 AM
|
#2 (permalink)
|
|
Contributing Member
Join Date: 03-06-04
Location: NY, CT, CA, AZ
Posts: 478
Latest Blog: None
|
Are you on a Linux or Windows system?
__________________
"90% of the game is half mental."
--Yogi Berra
Elizabeth Arden
|
|
|
11-06-2008, 09:29 AM
|
#3 (permalink)
|
|
Junior Member
Join Date: 11-06-08
Posts: 6
Latest Blog: None
|
I said at the bottom of my post mate, its a linux server running apache, mysql, cpanel etc, pretty much a standard shared webhosting server ...
|
|
|
11-06-2008, 09:42 AM
|
#4 (permalink)
|
|
Contributing Member
Join Date: 03-06-04
Location: NY, CT, CA, AZ
Posts: 478
Latest Blog: None
|
got it... I subconsciously ignore anything on the bottom that resembles a sig. This sounds like a nightmare of a project from a security and flexibility standpoint. Also, you'll be harvesting spam crap into MySQL.
Why not just install squirrelmail which would do all of that for you? It stores everything in MySQL. http://www.squirrelmail.org/docs/admin/admin-5.html
__________________
"90% of the game is half mental."
--Yogi Berra
Elizabeth Arden
|
|
|
11-07-2008, 01:32 AM
|
#5 (permalink)
|
|
Junior Member
Join Date: 11-06-08
Posts: 6
Latest Blog: None
|
Hey,
The whole idea of drafting us in is we avoid using pre-existing systems but the problem I can see, correct me if Im wrong is that squirrelmail access's a pop3 account correct? if this is the case how do i go about making thousands of email accounts? probably 10-15 will be added/changed/removed each day!
What Im after is a method of grabbing any incoming email and pushing this to a PHP file, from here I can then do basic spam checks, remove unknown users and a variety of other tasks as well such as linking to existing contacts and the like.
Its a very confusing topic and tbh, a lot of even the most hardcore of PHP coders have never really touched or looked into it before, I am aware of a |pipe feature built into the cpanel system that can push emails from sendmail to a CGI php script, however this throws an error for me when attempting it so was trying to find a better solution.
Any ideas how Squirrelmail would work? (its already installed on server as part of cpanel)
Thanks
Mike
|
|
|
11-07-2008, 07:59 AM
|
#6 (permalink)
|
|
Contributing Member
Join Date: 03-06-04
Location: NY, CT, CA, AZ
Posts: 478
Latest Blog: None
|
Take a look at the link above on squirrelmail. I'm pretty sure you can install it via yum or up2date install. Create a squirrelmail account and look at the tables to understand their structures. Then the process of replicating email accounts for squirrelmail would be done through a php script with a MySQL insert into the appropriate tables. Same thing with deleting, etc...
__________________
"90% of the game is half mental."
--Yogi Berra
Elizabeth Arden
|
|
|
11-10-2008, 09:05 AM
|
#7 (permalink)
|
|
v7n Mentor
Join Date: 07-24-06
Posts: 691
Latest Blog: None
|
You can create a catch-all mailbox in sendmail and then access it via POP3 or IMAP. So you won't need to create more mailboxes.
|
|
|
11-11-2008, 12:40 PM
|
#8 (permalink)
|
|
Junior Member
Join Date: 11-11-08
Posts: 1
Latest Blog: None
|
Hey Guys,
I'm looking for something similar...I'm working on setting up a members area for a travel company. When the client books a package online they will receive a free membership. I already have a PHP script in place that allows someone to register automatically and receive a validation link via email. The problem with that setup is anyone with a valid email address can create an account.
What I need is to parse out the clients email address, name & mailing address from an email generated from a third party. And only create an account when an email is received from the third party. These email messages always contain the same fields. So I think the best solution is to send those emails through to a PHP script via Sendmail.
The clients login info & address would then be stored in an SQL DB. The travel company would then send a welcome home letter to the customer telling them which URL to visit and what their login information is.
Now I did find this PHP script that (I am hoping) will handle an email once received...
PHP Code:
#!/usr/bin/php
<?php
// read from stdin
$fd = fopen("php://stdin", "r");
$email = "";
while (!feof($fd)) {
$email .= fread($fd, 1024);
}
fclose($fd);
// handle email
$lines = explode("\n", $email);
// empty vars
$from = "";
$subject = "";
$headers = "";
$message = "";
$splittingheaders = true;
for ($i=0; $i<count($lines); $i++) {
if ($splittingheaders) {
// this is a header
$headers .= $lines[$i]."\n";
// look out for special headers
if (preg_match("/^Subject: (.*)/", $lines[$i], $matches)) {
$subject = $matches[1];
}
if (preg_match("/^From: (.*)/", $lines[$i], $matches)) {
$from = $matches[1];
}
} else {
// not a header, but message
$message .= $lines[$i]."\n";
}
if (trim($lines[$i])=="") {
// empty line, header section has ended
$splittingheaders = false;
}
}
?>
My biggest problem right now is getting any email from reservation@travel-company.ca only to the PHP script.
Thanks for any advice and/or direction.
Steve
|
|
|
11-11-2008, 01:11 PM
|
#9 (permalink)
|
|
v7n Mentor
Join Date: 07-24-06
Posts: 691
Latest Blog: None
|
If it's on the same server and Apache is not jailed, simply read /var/mail/reservation .
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 08:12 AM.
© Copyright 2008 V7 Inc Powered by vBulletin Copyright © 2000-2009 Jelsoft Enterprises Limited.
|
|
|