E-mail met bijlage verzenden uit MySQL

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

H. Fokker

H. Fokker

01/09/2006 21:07:00
Quote Anchor link
Ik heb wat problemen met het ingepaste script van Eris. Het lukt maar niet de bijlage mee te krijgen in de E-mail die verzonden wordt.

Wat doe ik fout?

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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?
//-- Startobject


$mailer = new bericht();

if (!$show)
    $show = "sendmsg";

    
//-- Nieuwsbericht aanmaken en versturen

if ($show == "sendmsg")
{

        if ($submit && $check && $from && $email && $subject  && $msg)
        {

            $nl2brmsg = nl2br($msg);
            
            //-- Toon check
            echo "<table><tr valign=\"top\"><td align=\"right\"><font color=\"#00436E\"><b>Onderwerp&nbsp;</b></td><td>$subject</font><br></td></tr>";
            echo "<tr valign=\"top\"><td align=\"right\"><font color=\"#00436E\"><b>Bericht&nbsp;</b></td><td>$nl2brmsg</font><br></td></tr></table>";
            echo "<form method=\"post\" action=\"$PHP_SELF\">";
            echo "<input type=\"hidden\" name=\"show\" value=\"$show\">";
            echo "<input type=\"hidden\" name=\"from\" value=\"$from\">";
            echo "<input type=\"hidden\" name=\"email\" value=\"$email\">";
            echo "<input type=\"hidden\" name=\"subject\" value=\"$subject\">";
            echo "<input type=\"hidden\" name=\"file\" value=\"$file\">";
            echo "<input type=\"hidden\" name=\"msg\" value=\"$msg\">";
            echo "<input type=\"submit\" name=\"submit\" value=\"Versturen\" class=\"submit\">";
            echo "</form>";
        }

        elseif ($submit && !$check && $from && $email && $subject && $msg)
        {

    
    //-- Zend bericht
    
            if ($mailer->SendMail($subject, $msg)) { echo "<font color=\"#009900\"><b>Het bericht is succesvol verstuurd</b></font>"; }
            else { echo "<font color=\"#D3180B\"><b>Het bericht is niet verstuurd, probeer het opnieuw</b></font>"; }
        }

        else
        {
        if ($submit && (!$subject || !$from || !$email || !$msg)) { echo "<font color=\"#D3180B\"><b>Je bent een veld vergeten in te vullen</b></font>"; }
        
        echo "<form method=\"POST\" action=\"$PHP_SELF\">";
        echo "<input type=\"hidden\" name=\"show\" value=\"$show\">";
        echo "<input type=\"hidden\" name=\"check\" value=\"1\"><table>";
        echo "<tr><td><b><font color=\"#00436E\">Afzender</td><td><input type=\"text\" name=\"from\" value=\"$from\" size=\"25\"><br></td></tr>";
        echo "<tr><td><b><font color=\"#00436E\">E-mailadres&nbsp;</td><td><input type=\"text\" name=\"email\" value=\"$email\" size=\"25\"><br></td></tr>";
        echo "<tr><td><b><font color=\"#00436E\">Onderwerp</font></b></td><td><input type=\"text\" name=\"subject\" value=\"$subject\" size=\"25\"></td></tr>";
        echo "<tr><td><b><font color=\"#00436E\">Bijlage</font></b></td><td><input type=\"file\" name=\"file\" value=\"$file\" size=\"25\"></td><tr><br><br><br>";
        echo "<tr valign=\"top\"><td><b><font color=\"#00436E\">Bericht</font></b></td><td><textarea name=\"msg\" cols=\"65\" rows=\"10\">$msg</textarea></td></tr>";
        echo "<tr valign=\"top\"><td></td><td><input type=\"submit\" name=\"submit\" value=\"Bericht eerst bekijken\" class=\"submit\">";
        echo "</td></tr></table></form>";
    }
}



class bericht
{
    // Zend bericht
    function SendMail($subject, $msg)
    {
        
        $sql = "SELECT email2 FROM users WHERE rang = '15'";
        $res = mysql_query($sql);
        
        while ($row = mysql_fetch_array($res))
        {

            $to = "".$row['email2']."";
            $bericht  = "<b><font color=\"#00436e\" size=\"2\" face=\"Verdana\">$msg\r\n</b></font><br><br>";

            $headers  = "From: ".$_POST['from']." <".$_POST['email'].">\r\n";
            $headers .= "Reply-To: ".$_POST['from']." <".$_POST['email'].">\r\n";
            $headers .= "MIME-Version: 1.0\r\n";
            $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

DEFINE('bound',md5(uniqid(time())));

         if ($_FILES['file']['name'] != '')
         {

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

            $headers .= "Content-Type: multipart/mixed; boundary=\"".bound."\"\r\n";
            $headers .= "Content-Disposition:  attachment\r\n";
            
    //readfile
            
            $fp = fopen($_FILES['file']['tmp_name'],'r');
            $bestand = fread($fp,$_FILES['file']['size']);
            fclose($fp);
            
    //generenen een body
    
            $body  = "This is a multi-part message in MIME format.\r\n";
            $body .= "\r\n";
            $body .= "--".bound."\r\n";
            $body .= "Content-Type: text/plain; charset=iso-8859-1\r\n";
            $body .= "Content-Transfer-Encoding: 7bit\r\n";
            $body .= "\r\n";
            $body .= "--".bound."\r\n";
            $body .= "Content-Type: application/octet-stream; name=".$_FILES['file']['name']."\r\n";
            $body .= "Content-Transfer-Encoding: base64\r\n";
            $body .= "Content-disposition: attachment\r\n";
            $body .= "\n";
            $body .= chunk_split(base64_encode($bestand )) . "\r\n";

            mail($to, $subject, $bericht, $headers, $body);
            }

            else { echo 'De bijlage is te groot'; }
            }

        
        else
        {
            mail($to, $subject, $bericht, $headers);
        }
    }

    return $res;
      }
}

?>
Gewijzigd op 01/01/1970 01:00:00 door H. Fokker
 
PHP hulp

PHP hulp

21/11/2024 20:47:14
 
PHP Newbie

PHP Newbie

01/09/2006 21:11:00
Quote Anchor link
Plaats ff code tags, dan wordt het iig wat leesbaarder
 
H. Fokker

H. Fokker

01/09/2006 21:35:00
Quote Anchor link
Dat is een goed plan! Het staat er.
Gewijzigd op 01/01/1970 01:00:00 door H. Fokker
 
- SanThe -

- SanThe -

01/09/2006 22:53:00
Quote Anchor link
Volgens mij staat de return $res; te vroeg.

Dus niet
mail($to, $subject, $body, $headers);
return $res;
}
}

maar
mail($to, $subject, $body, $headers);
}
return $res;
}
 
H. Fokker

H. Fokker

01/09/2006 23:28:00
Quote Anchor link
Bedankt! Dat was inderdaad een van de problemen.

Iemand een idee waarom de bijlage niet wordt meeverzonden?
Gewijzigd op 01/01/1970 01:00:00 door H. Fokker
 



Overzicht Reageren

 
 

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.