Dus
- je hebt een server
- je krijgt e-mails
- je wilt ze opslaan in een mysql-database
Cpanel-configuratie
- ga naar cpnal email forwarder
- voeg een nieuwe toe
- redirect naar PATH -> /home/your_user/whatever/php.script.php
Php-script (u moet mogelijk het pad "/usr/bin/php -q" wijzigen, afhankelijk van uw serverconfiguratie)
#!/usr/bin/php -q
<?php
chdir(dirname(__FILE__));
$fd = fopen("php://stdin", "r");
$email = "";
while (!feof($fd)) {
$email .= fread($fd, 1024);
}
fclose($fd);
if(strlen($email)<1) {
die();
}
// handle email
$lines = explode("\n", $email);
// empty vars
$from = "";
$to="";
$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];
}
if (preg_match("/^To: (.*)/", $lines[$i], $matches)) {
$to = $matches[1];
}
} else {
// not a header, but message
$message .= $lines[$i]."\n";
}
if (trim($lines[$i])=="") {
// empty line, header section has ended
$splittingheaders = false;
}
}
Werkt ook op shared hosting! :)
Alles wat je hoeft toe te voegen is de mysql-insert en gebruik de hierboven gedefinieerde variabelen. Weet u hoe u een mysql-database van php moet gebruiken? Of heb je daar ook hulp bij nodig?