emaildatabase-script

Gesponsorde koppelingen

PHP script bestanden

  1. emaildatabase-script

« Lees de omschrijving en reacties

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?
//show all errors, Very usefull while scripting. It shows al errors and warnings
error_reporting(E_ALL);
//include config.php for settings
//If you doen't want to use it. please leave it blank.

$mail_user_id = 'emailadress';//used for the script not your private mail or your ptivate mail will be inserted!
//email password 'password';

$mail_password = '';
//database host
$host = 'localhost';//often localhost
//database name

$database_name = 'database';
//database username
$database_username = 'username';
//database password
$database_password = 'password';
//dateformat in database follow iso standaard
$iso = 'Y-m-d H:i:s';//php 5 replace it for 'c' or keep it
mysql_select_database($databse_name,mysql_connect($host,$databse_username,$database_password));
//conect to mailserver
//dit nog even aanpassen. Het werkt alleen als de mailserver op local host staat :/ en dat is niet iedeaal.

if($mbox = imap_open("{localhost:143}INBOX",$mail_user_id,$mail_password))
{

//check mail
$mtnum = imap_num_msg($mbox);
  if($mtnum > 0){
//get trough all messages with a for loop.
for($mnum = 1;$mnum <= $mtnum; $mnum++){
        //fetch content due there is a change that this page has a multi header. (as text and image) imap_body($mbox,$mnum); doesn't work.
        $mcontent = imap_fetchbody($mbox,$mnum,1);
    //fetch headers
    $mheader = imap_headerinfo($mbox,$mnum);
        //replace the emil in header info
        $mheader->fromaddress = preg_replace("/<(.*?)\>/si", "", $mheader->fromaddress);
        //recive the structure of the email
        $mstructure = imap_fetchstructure($mbox,$mnum);
        //check this email has a mixed subtype.
        if($mstructure->subtype == 'MIXED')
        {

        //loop trough all parts of the email
        for($mpart = 1;!empty($mstructure->parts[$mpart]->dparameters[0]->value);$mpart++){
        //revice any data from the attacment
        $mdata = imap_fetchbody($mbox,$mnum,$mpart + 1);
        //decode the 64 coded string to a string who could understood by PHP for creating the image form a string
        $mdecode = base64_decode($mdata);
        //create image from string.
        $mimage = imagecreatefromstring($mdecode);
        $mfilename = $mstructure->parts[$mpart]->dparameters[0]->value;
        //recive the size of the image.
        //getimagesize($mimage); doesn't work.

        $mwidth = imagesx($mimage);
        $mheigth = imagesy($mimage);
        //check max size;
        //resize the image.

        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);
        //check if the image name allready exist if true delete the older one
        if(file_exists('images/upload/'.$mfilename)){
        unlink('images/upload/'.$mfilename);
        }

        //only gif, jpg,jpeg and png are suported corectly.
        if(($mstructure->parts[$mpart]->subtype == 'jpg') or ($mstructure->parts[$mpart]->subtype == 'jpeg')){
        //create a jpeg file.
        imagejpeg($mnewimage,'images/upload/'.$mfilename);

        }
else{
        //create a png/gif file. In GD 1.6 or higer imagegif isn't supproted
        imagepng($mnewimage,'images/upload/'.$mfilename);
        }
        }
else{
        if(file_exists('images/upload/'.$mfilename)){
        unlink('images/upload/'.$mfilename);
        }

        //only gif, jpg,jpeg and png are suported
        if(($mstructure->parts[$mpart]->subtype == 'jpg') or ($mstructure->parts[$mpart]->subtype == 'jpeg')){
        imagejpeg($mimage,'images/upload/'.$mfilename);
        }
else{
        imagepng($mimage,'images/upload/'.$mfilename);
        }
        }

//ubbcode: Replace * for a [ (Ubb phrasesr suxs here ^^)
        $mcontent.='*img]'.$domain.'images/upload/'.$mfilename.'[/img]\n';
        imagedestroy($mimage);
        }
        }

//insert in database
//make your own database query

$sql = "INSERT INTO `".$prefix."weblog` (`subject`,`date`,`content`,`author`) VALUES ('".$mheader->subject."','".date($iso, strtotime($mheader->date))."','".onpost($mcontent)."','".$mheader->fromaddress."')";
mysql_query($sql);
//send message to trashbin
imap_delete($mbox,$mnum);
}
}

//Delete al messages form the "thrashbin"
imap_expunge($mbox);
//disconect form server
imap_close($mbox);
}

?>

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.