Beste sd leden,
Ik heb nu een script wat gegevens inleest uit een imap mailbox.
Nu wil ik deze gegevens schrijven naar een database.
Maar de gegevens zijn dusdanig dat ik alleen het bericht en niet alle zooi eromheen in de database wil.
Iemand ervaring met dit soort praktijken?
- imap in php - Naar database schrijven?
-
12-02-2006, 16:03 #1
- Berichten
- 427
- Lid sinds
- 19 Jaar
imap in php - Naar database schrijven?
-
-
12-02-2006, 19:02 #2
- Berichten
- 427
- Lid sinds
- 19 Jaar
Opgelost:
PHP Code:<?
include_once("config.php");
$mail_user_id = '';
$mail_password = "";
$iso = 'Y-m-d H:i:s';
if($mbox = imap_open("{localhost/pop3:110}INBOX",$mail_user_id,$mail_password))
{
$mtnum = imap_num_msg($mbox);
if($mtnum > 0){
for($mnum = 1;$mnum <= $mtnum; $mnum++){
$mcontent = imap_fetchbody($mbox,$mnum,1);
$mheader = imap_headerinfo($mbox,$mnum);
$mheader->fromaddress = preg_replace("/<(.*?)\>/si", "", $mheader->fromaddress);
$mstructure = imap_fetchstructure($mbox,$mnum);
if($mstructure->subtype == 'MIXED')
{
for($mpart = 1;!empty($mstructure->parts[$mpart]->dparameters[0]->value);$mpart++){
$mdata = imap_fetchbody($mbox,$mnum,$mpart + 1);
$mdecode = base64_decode($mdata);
$mimage = imagecreatefromstring($mdecode);
$mfilename = $mstructure->parts[$mpart]->dparameters[0]->value;
$mwidth = imagesx($mimage);
$mheigth = imagesy($mimage);
if($photow < $mwidth){
$mprop = $photow / $mwidth;
$mnewwidth = $photow;
$mnewheight = $mheigth * $mprop;
$mnewheight = round($mnewheight);
$mnewimage = imagecreatetruecolor($mnewwidth, $mnewheight);
imagecopyresampled($mnewimage, $mimage, 0, 0, 0, 0, $mnewwidth, $mnewheight, $mwidth, $mheigth);
if(file_exists('images/upload/'.$mfilename)){
unlink('images/upload/'.$mfilename);
}
if(($mstructure->parts[$mpart]->subtype == 'jpg') or ($mstructure->parts[$mpart]->subtype == 'jpeg')){
imagejpeg($mnewimage,'images/upload/'.$mfilename);
}else{
imagepng($mnewimage,'images/upload/'.$mfilename);
}
}else{
if(file_exists('images/upload/'.$mfilename)){
unlink('images/upload/'.$mfilename);
}
if(($mstructure->parts[$mpart]->subtype == 'jpg') or ($mstructure->parts[$mpart]->subtype == 'jpeg')){
imagejpeg($mimage,'images/upload/'.$mfilename);
}else{
imagepng($mimage,'images/upload/'.$mfilename);
}
}
$mcontent.='*img]'.$domain.'images/upload/'.$mfilename.'[/img]\n';
imagedestroy($mimage);
}
}
$sql = "INSERT INTO `mail` (onderwerp,date,content,author) VALUES ('".$mheader->subject."','".date($iso, strtotime($mheader->date))."','".$mcontent."','".$mheader->fromaddress."')";
mysql_query($sql) or die(mysql_error());
imap_delete($mbox,$mnum);
}
}
imap_expunge($mbox);
imap_close($mbox);
}
?>
Plaats een
- + Advertentie
- + Onderwerp
Marktplaats
Webmasterforum
- Websites algemeen
- Sitechecks
- Marketing
- Domeinen algemeen
- Waardebepaling
- CMS
- Wordpress
- Joomla
- Magento
- Google algemeen
- SEO
- Analytics
- Adsense
- Adwords
- HTML / XHTML
- CSS
- Programmeren
- PHP
- Javascript
- JQuery
- MySQL
- Ondernemen algemeen
- Belastingen
- Juridisch
- Grafisch ontwerp
- Hosting Algemeen
- Hardware Info
- Offtopic