Hey Loony,
Thanks for that script idea, but I don't think it would work for me, I can show you a sample script i've been testing, but it doesn't work consistently. Sometimes some emails are read 2 or 3 times, some are skipped it just doesn't work consistently... ill post it below:
Here is the include:
<?php
/**************************************************************
MMS/PHOTOBLOG CLASS
Version 1.7
Released 17 Dec 2005
by ruben @ bolink.org
http://www.bolink.org
**************************************************************/
// config!
$pop3_address = "mms@allen.dj";
$pop3_server = "localhost";
$password = "***********";
$images_dir = "./imgtst/";
$date_format = "d-m-Y";
$db_host = "localhost";
$db_user = "testmms";
$db_password = "*************";
$db_name = "testmms";
$db_table = "mms";
// connecting to db
@mysql_connect($db_host, $db_user, $db_password) or header("location: $url?error=1");
@mysql_select_db($db_name) or header("location: $url?error=1");
// check if table exist
$url = "http://bolink.org/projects/mms/error.php"; // for error handling
$check = mysql_query("SELECT * FROM `$db_table` LIMIT 0,1");
if (!$check) {
$query = "CREATE TABLE `$db_table` (id int(11) NOT NULL auto_increment,type text NOT NULL,subject text NOT NULL,toaddress text NOT NULL,fromaddress text NOT NULL,date text NOT NULL,UNIQUE KEY id (id)) TYPE=MyISAM; ";
$result = mysql_query($query) or header("location: $url?error=1");
}
// check if directory is writable
if (!is_writable($images_dir)) {
@mkdir("$images_dir") or header("location: $url?error=2");
@chmod($images_dir, 0777) or header("location: $url?error=3");
}
// check if imap works
if (!function_exists('imap_open')) {
header("location: $url?error=7");
}
// open mailbox and get all emails from server
if (! $mail = @imap_open("{".$pop3_server.":143/imap/notls}INBOX", "$pop3_address", "$password")) {
header("location: $url?error=4");
}
$headerstrings = imap_headers($mail);
foreach($headerstrings as $headerstring) {
preg_match("/[0-9]/", $headerstring, $number);
// parse message
$header = imap_fetchheader($mail, $number[0]);
preg_match("/Date: (.*)?[\+|-]/", $header, $date);
$date = htmlentities($date[1]);
$imap = imap_fetchstructure($mail, $number[0]);
if (! empty($imap->parts)) {
for ($i = 1, $j = count($imap->parts); $i < $j; $i++) {
$msg = imap_fetchbody($mail, $number[0], $i + 1);
$part = $imap->parts[$i];
$headers = imap_header($mail, $number[0]);
$from = $headers->from;
$addr = "".$from[0]->mailbox."@".$from[0]->host."";
$subj = $headers->subject;
$to = $headers->toaddress;
$date = date($date_format, strtotime(substr($headers->Date, 0, 22)));
$subj = preg_replace('/^.*Q\?(.*?)\?=$/', '\\1', $subj);
$subj = str_replace("_", " ", $subj);
$subj = str_replace("=2E", ".", $subj);
$subj = addslashes($subj);
if ($part->type == "3") {
$ext = "3gp";
} else if ($part->type == "5") {
$ext = "jpg";
}
$query = "INSERT INTO `$db_table` VALUES ('NULL','$ext','$subj','$to','$addr','$date')";
$result = mysql_query($query) or header("location $url?error=5");
$count = mysql_insert_id();
if (! $handle = fopen("$images_dir/".$count.".$ext", "w")) {
header("location: $url?error=6");
}
fwrite($handle, imap_base64($msg));
fclose($handle);
}
}
}
imap_delete($mail, $number[0]);
imap_expunge($mail);
imap_close($mail);
?>
<?
include("mms.class.php");
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>MMS TEST BY: DJ ALLEN</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<style type="text/css">
body {
color: #444;
}
td { border: 2px solid gray; }
table { font: 10px Verdana, sans-serif; border: 0px solid black; }
a { text-decoration: none; color: white; }
</style>
</head>
<body>
<table>
<tr><td colspan="2" align="center"><h1>Photo MMS Test By: DJ ALLEN PRODUCTIONS<br>
Send Your Pic To: [email]mms@allen.dj[/email]</h1></td></tr>
<?
$query = "SELECT * FROM `$db_table` order by id DESC limit 50";
$result = mysql_query($query) or die(mysql_error());
while ($mms = mysql_fetch_array($result, MYSQL_ASSOC)) {
if ($mms[type] == "3gp") {
echo "<tr><td colspan=\"2\"><a href=\"$images_dir$mms[id].3gp\" title=\"click to zoom\">";
echo "<object classid=\"clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B\" width=\"320\" height=\"200\" codebase=\"http://www.apple.com/qtactivex/qtplugin.cab\">";
echo "<param name=\"SRC\" value=\"$images_dir$mms[id].3gp\">";
echo "<param name=\"AUTOPLAY\" value=\"false\">";
echo "<param name=\"type\" value=\"video/quicktime\">";
echo "<param name=\"CONTROLLER\" value=\"true\">";
echo "<embed src=\"$images_dir$mms[id].3gp\" width=\"300\" height=\"200\" autoplay=\"false\" controller=\"true\" type=\"video/quicktime\" pluginspage=\"http://www.apple.com/quicktime/download/\">";
echo "</object>";
echo "</a></td></tr><tr>";
} else {
echo "<tr><td colspan=\"2\"><a href=\"$images_dir$mms[id].jpg\" title=\"click to zoom\">";
echo "<img alt=\"click to zoom\" width=\"300\" src=\"$images_dir$mms[id].jpg\"></a></td></tr><tr>";
}
echo "<td width=\"100\">text:</td>";
echo "<td>$mms[subject]</td></tr><tr>";
echo "<td>date:</td>";
echo "<td>$mms[date]</td></tr><tr>";
echo "<td>from:</td>";
echo "<td>$mms[fromaddress]</td></tr><tr>";
echo "<td>to:</td>";
echo "<td>$mms[toaddress]</td></tr>";
}
?>
</table>
</body>
</html>
Any ideas as to why that might be happening? Duplicate or Triple emails? Some not coming through? Some of the attachments not coming through? It's weird that it does it... 😕
-Allen