email til sql
Hej ExpJeg har et problem med at få emails over i database.
Det skal bruges til noget email til sms.
PRoblemet er at det kode jeg har går gennem modtagerlisten og er der 3 modtager så skriver den første modtager ved hver insert i databasen.
Der kommer de 3 mails ind i databasen men kun med første modtager.
Skal have den til at tage modtager listen og giver hver insert i db den rette modtager.
Er det noget nogen kan hjælpe med ?
koden er her:
<?
include("./PHPmail2system.conf.php");
include("./PHPmail2system.functions.lib.php");
$ServerName = "{". $Mail_ServerName_conf ."/". $Mail_ServerAccessProtocol_conf .":". $Mail_ServerAccessPort_conf ."}INBOX";
$UserName = $Mail_UserName_conf;
$PassWord = $Mail_PassWord_conf;
/*
OPENING MAILBOX
*/
$mbox = imap_open($ServerName, $UserName,$PassWord) or die("Could not open imap Mailbox - try again later!");
if ($hdr = imap_check($mbox)) {
// echo "Num Messages " . $hdr->Nmsgs ."\n\n<br><br>";
$msgCount = $hdr->Nmsgs;
} else {
echo "failed";
}
$MN=$msgCount;
$overview=imap_fetch_overview($mbox,"1:$MN",0);
$size=sizeof($overview);
/*
START LOOPING THROUGH ALL THE MESSAGES
*/
for($ss=$size-1;$ss>=0;$ss--){
/*
GET HEADER DATA
*/
$val=$overview[$ss];
$msgno=$val->msgno;
$from=$val->from;
$dato=$val->date;
$subj=$val->subject;
$toadr=$val->to;
$hdrinfo = imap_headerinfo($mbox,$msgno,1024,"localhost");
$toadr = $hdrinfo->to[0]->mailbox ."@". $hdrinfo->to[0]->host;
/*
TRANSFORM NON ANSI CHARACTERS IN SUBJECT AND SENDER_INFO ($from)
*/
$from = ereg_replace("\"","",$from);
$subj = transformstr(imap_utf8($subj));
$from = transformstr(imap_utf8($from));
/*
FORMAT DATE DISPLAY INTO DANISH FORMAT (e.g. dd mm yyyy hh:mm:ss)
*/
list($dayName,$day,$month,$year,$time,$timezone) = split(" ",$dato);
$dato = $year ."-". getMonthInt($month) ."-". $day ." ". $time;
$dateFolder = $year ."-". getMonthInt($month) ."-". $day;
/*
SPLIT SENDER_INFO ($from) INTO "NAME <EMAIL>" FORMAT
*/
list($fromName,$fromemailadresse) = split(" <",$from);
$fromemailadresse = ereg_replace(">","",$fromemailadresse);
/* ATTACHMENT HANDLING */
$struct = imap_fetchstructure($mbox,$msgno);
$contentParts = count($struct->parts);
if ($contentParts >= 2) {
$filecounter = 0;
for ($i=2;$i<=$contentParts;$i++) {
$att[$i-2] = imap_bodystruct($mbox,$msgno,$i);
}
for ($k=0;$k<sizeof($att);$k++) {
if ($att[$k]->parameters[0]->value == "us-ascii" || $att[$k]->parameters[0]->value == "US-ASCII") {
if ($att[$k]->parameters[1]->value != "") {
$strFileName = $att[$k]->parameters[0]->value;
$fileSize = $att[$k]->bytes;
$strFileType = strrev(substr(strrev($strFileName),0,4));
$fileContent = imap_fetchbody($mbox,$msgno,$k+2);
/*
CALL FUNCTION TO STORE THE FILE
*/
$fileNameToStore = storeFile($strFileType,$strFileName,$fileContent,$fileSize,$dateFolder,$storagePolicy_conf,$placeOnFS_conf);
/*
STORE THE FILENAME IN ARRAY
*/
$fileNameArray[$filecounter] = $fileNameToStore;
}
} elseif ($att[$k]->parameters[0]->value != "iso-8859-1" && $att[$k]->parameters[0]->value != "ISO-8859-1") {
$strFileName = $att[$k]->parameters[0]->value;
$fileSize = $att[$k]->bytes;
$strFileType = strrev(substr(strrev($strFileName),0,4));
$fileContent = imap_fetchbody($mbox,$msgno,$k+2);
/*
CALL FUNCTION TO STORE THE FILE
*/
$fileNameToStore = storeFile($strFileType,$strFileName,$fileContent,$fileSize,$dateFolder,$storagePolicy_conf,$placeOnFS_conf);
/*
STORE THE FILENAME IN ARRAY
*/
$fileNameArray[$filecounter] = $fileNameToStore;
}
$filecounter++;
}
}
/* END OF ATTACHMENT HANDLING */
/*
GET THE MESSAGE BODY
*/
// get plain text
$dataTxt = get_part($mbox, $msgno, "TEXT/PLAIN");
// get HTML text
$dataHtml = get_part($mbox, $msgno, "TEXT/HTML");
if ($dataHtml != "") {
// $msgBody = transformHTML($dataHtml);
$msgBody = $dataHtml;
} else {
$msgBody = ereg_replace("\n","<br>",$dataTxt);
$msgBody = preg_replace("/([^\w\/])(www\.[a-z0-9\-]+\.[a-z0-9\-]+)/i","$1http://$2", $msgBody); //make sure there is an http:// on all URLs
$msgBody = preg_replace("/([\w]+:\/\/[\w-?&;#~=\.\/\@]+[\w\/])/i","<A TARGET=\"_blank\" HREF=\"$1\">$1</A>", $msgBody); //make all URLs links
$msgBody = preg_replace("/([\w-?&;#~=\.\/]+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?))/i","<A HREF=\"mailto:$1\">$1</A>",$msgBody);
}
if (saveTheMail($fromemailadresse,$fromName,$toadr,$subj,$from,$dato,$fileNameArray,$msgBody,$MySQL_ServerName_conf,$MySQL_UserName_conf,$MySQL_PassWord_conf,$MySQL_DataBase_conf,$MySQL_Normalized_conf)) {
imap_delete($mbox,$msgno);
imap_expunge($mbox);
} else {
if ($errorReporting_conf == 1 && strlen($errorReportingEmail_conf) > 5) {
mail($errorReportingEmail,"Error - storing mail","The Email from\n$fromName $fromemailadresse\nCould not be stored in MySQL\n\nThe mail is still in the mailbox on the server.");
}
}
unset($fileNameArray);
unset($mail_attachmentsArray);
unset($att);
}
/*
CLOSE THE MAILBOX
*/
imap_close($mbox);
?>