email-formulier-met-bijlage

Gesponsorde koppelingen

PHP script bestanden

  1. email-formulier-met-bijlage

« 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
<?php
//mail formulier voor bijlage
$email ='[email protected]';
//geneer boundary
DEFINE('bound',md5(uniqid(time())));
//check request method

    if($_SERVER['REQUEST_METHOD'] == 'POST')
    {

         //if file upload send with email as mixed
         if(!empty($_FILES['file']['name']))
         {

            //check filesize
             if($_FILES['file']['size'] < 1024*50)
             {

                  $headers = "From: ".$_POST['from']." <".$_POST['email'].">\r\n";
                $headers .= "Reply-To: ".$_POST['from']." <".$_POST['email'].">\r\n";
                   $headers .= "MIME-Version: 1.0\r\n";
                   //email bestaat uit meerdere  bestanden dus vertel wat de scheidings teken is en dat het een multipart is
                   $headers .= "Content-Type: multipart/mixed; boundary=\"".bound."\"\r\n";
                   //we zenden een attachment mee
                   $headers .= "Content-Disposition:  attachment\r\n";
                   //readfile
                   $fp = fopen($_FILES['file']['tmp_name'],'r');
                   $bestand = fread($fp,$_FILES['file']['size']);
                   fclose($fp);
                   //create body
                   //generenen een body. Dit is een multi part gezeik

                   $body.= "This is a multi-part message in MIME format.\r\n";
                   $body.= "\r\n";
                //boundary
                $body.= "--".bound."\r\n";
                //content type + charater set (iso in dit geval)
                $body.= "Content-Type: text/plain; charset=iso-8859-1\r\n";
                //codering (7 bit)
                $body.= "Content-Transfer-Encoding: 7bit\r\n";
                $body.= "\r\n";
                //het bericht
                $body.= $_POST['bericht'] ."\r\n";
                //boundary
                $body.= "--".bound."\r\n";
                //content type + naam bestand (database.sql)
                $body .= "Content-Type: application/octet-stream; name=".$_FILES['file']['name']."\r\n";
                //codering
                $body .= "Content-Transfer-Encoding: base64\r\n";
                //als bijlage toegevoegd
                $body.= "Content-disposition: attachment\r\n";
                $body .= "\n";
                //de inhoud van het bestand
                $body .= chunk_split(base64_encode($bestand )) . "\r\n";
                mail($email,$_POST['subject'],$body,$headers);
                echo 'Email (Met een bijlage) is verzonden';
            }

            else
            {
                 echo 'Bestands groote is te groot';
             }
        }

        else
        {
            $headers = "From: ".$_POST['from']." <".$_POST['email'].">\r\n";
               $headers .= "Reply-To: ".$_POST['from']." <".$_POST['email'].">\r\n";
               $headers .= "MIME-Version: 1.0\r\n";
               $bericht = $_POST['bericht'];
               mail($email,$_POST['subject'],$bericht,$headers);
               echo 'Email (Zonder een bijlage) is verzonden';
         }
     }

     else
     {
        //mail formulier je moet zelf het fomullier maken

        echo "<form action=\"" . $_SERVER['PHP_SELF'] . "\" method=\"POST\" enctype=\"multipart/form-data\">";
         echo "Naam: <input type='text' name='from'><br>";
         echo "Email:<input type='text' name='email'><br>";
         echo "Onderwerp:<input type='text' name='subject'><br>";
         echo "Bestand:<input type='file' name='file'><br>";
         echo "Bericht:<textarea name='bericht'></textarea><br />";
        echo "<input type=\"submit\" value=\"Verzenden\">";
    }

?>

 
 

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.