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