Formulier met bijlages

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

Mary Grooteman

Mary Grooteman

31/05/2016 18:04:11
Quote Anchor link
Hallo,
Met kunst- en vliegwerk heb ik op basis van een bestaand (niet zelf gemaakt) php formulier een vrij uitgebreid formulier gemaakt met inputs, selectfields, textarea's en radiobuttons. De errormeldingen, google recaptcha doen het (!), de bevestigingsmail en resultaten komen netjes aan, én alle invoer blijft staan na refresh en ook nadat je errormeldingen hebt gehad. Heeft een weekje geduurd.
So far so good.
Maar nu wil ik die attachments in de mail meesturen. Wat wel gelukt is is dat de bijlages in een map komen. Maar daar kan degene die ze nodig heeft niet zomaar even uithalen.
HOE krijg ik ze toch in de mail, ik ben er bijna...
Ik heb ook ooit een werkend formulier gemaakt met class.phpmailer en fgcontactform dat wel attachments in de mail meestuurt, maar daar krijg ik google recaptcha weer niet werkend, en geen bevestigingsmail!
Na weken 10 miljoen dingen geprobeerd te hebben vraag ik raad aan iemand die me hiermee kan helpen...
Alvast heel erg bedankt,
groetjes, Mary
 
PHP hulp

PHP hulp

29/03/2024 13:15:45
 
- Ariën  -
Beheerder

- Ariën -

31/05/2016 18:09:56
Quote Anchor link
met AddAttachment() in phpMailer kan je prima bijlages aan je mail toevoegen. Dit zou geen conflicten met je reaptcha mogen opleveren, of je doet iets vreemd in je code.

Laat anders eens je relevante code eens zien waarmee je het formulier verstuurt.
 
Mary Grooteman

Mary Grooteman

31/05/2016 18:29:19
Quote Anchor link
Dankjewel voor je reactie! Ik zal niet alles neerzetten, want er is heel veel html ook, maar hier (hopelijk) relevante code:
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
<?php

$arrErrors
= array();
//Alleen valideren bij submit
if (!empty($_POST['Submit'])) {
    if ($_POST['Discipline']=='')
        $arrErrors['Discipline'] = 'Vul alstublieft uw discipline in.';
    if ($_POST['Naam_verwijzer']=='')
        $arrErrors['Naam_verwijzer'] = 'Vul alstublieft uw naam in.';
    if ($_POST['Email_verwijzer']=='')
        $arrErrors['Email_verwijzer'] = 'Vul alstublieft uw e-mailadres in.';
    if ($_POST['Tel_verwijzer']=='')
        $arrErrors['Tel_verwijzer'] = 'Vul alstublieft uw telefoonnummer in.';
    if ($_POST['Naam_patient']=='')
        $arrErrors['Naam_patient'] = 'Vul alstublieft de naam van de patiënt in.';
    if ($_POST['Email_patient']=='')
        $arrErrors['Email_patient'] = 'Vul alstublieft het e-mailadres van de patient in.';
    if ($_POST['BSN']=='')
        $arrErrors['BSN'] = 'Vul alstublieft het BSN-nummer van de patient in.';
    if ($_POST['Tel_patient']=='')
        $arrErrors['Tel_patient'] = 'Vul alstublieft het telefoonnummer van de patient in.';
  
   $email;$comment;$captcha;
        if(isset($_POST['post'])){
          $email=$_POST['post'];
        }
if(isset($_POST['comment'])){
          $email=$_POST['comment'];
        }
if(isset($_POST['g-recaptcha-response'])){
          $captcha=$_POST['g-recaptcha-response'];
        }

        if(!$captcha)$arrErrors['captcha'] = 'Vink alstublieft de captcha aan.';
        $secretKey = "6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe";
        $ip = $_SERVER['REMOTE_ADDR'];
        $response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&response=".$captcha."&remoteip=".$ip);
        $responseKeys = json_decode($response,true);
        
    
    if (count($arrErrors) == 0) {
        $Discipline         =   $_POST['Discipline'];
        $Naam_verwijzer     =    $_POST['Naam_verwijzer'];
        $Email_verwijzer    =     $_POST['Email_verwijzer'];
        $Tel_verwijzer         =     $_POST['Tel_verwijzer'];
        $Naam_patient         =     $_POST['Naam_patient'];
        $Email_patient        =    $_POST['Email_patient'];
        $Tel_patient        =     $_POST['Tel_patient'];
        $BSN                 =     $_POST['BSN'];
        $Parodontaal        =     $_POST['Parodontaal']; //select
        $Paro_anders        =   $_POST['Paro_anders'];//textarea
        $Extracties         =   $_POST['Extracties']; //ja-nee radiobutton
        $Elementen          =   $_POST['Elementen'];//textarea
        $Voorbehandeld      =   $_POST['Voorbehandeld'];//ja-nee radiobutton
        $Voorbehandeling    =     $_POST['Voorbehandeling'];//select
        $Nazorg             =   $_POST['Nazorg'];//textarea
        $Premedicatie        =     $_POST['Premedicatie'];//ja-nee radiobutton
        $Antibioticum       =   $_POST['Antibioticum'];//welk antibioticum
        $Nazorg_doorwie     =   $_POST['Nazorg_doorwie'];//ja-nee radiobutton
        $Implantologisch    =   $_POST['Implantologisch'];//select
        $Impl_anders        =   $_POST['Impl_anders'];//textarea
        $Suprastructuur     =   $_POST['Suprastructuur'];//ja-nee radiobutton
        $Cosmetisch            =     $_POST['Cosmetisch'];//select
        $Cosm_anders        =   $_POST['Impl_anders'];//textarea
        $Planning            =     $_POST['Planning'];//textarea
        $files                =     $_POST['files'];//uploads
      
        $headers  = 'MIME-Version: 1.0' . "\r\n";
        $headers .= 'Content-type: text/html; multipart/alternative;charset=iso-8859-1' . "\r\n";
        $headers .= "From: Verwijzing parodontoloog <[email protected]>" . "\r\n";

        $to            =        "[email protected]"; //waarnaartoe
        $subject    =        "Verwijzing van $Discipline voor de parodontoloog";
        $attachment =       "chunk_split(base64_encode(file_get_contents('attachment.zip')))";
        $styletag    =        "style=\"font-weight:bold;border-top: 2px solid #ff8800; line-height: 150%;\"">
        $message    =        "
                                <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"
                                \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">
                                <html>
                                <head>
                                <title>Verwijzing verzonden</title>
                                <meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">
                                </head>
                                <body>
                                    <span style=\"font-family:sans-serif;\">invuldatum: "
.date("d-m-Y H:i")."</span>
                                    <br><br>
                                    <table style=\"font-family:sans-serif; line-height: 170%; background-color: #f4f4f4; border-collapse: collapse; width:100%; margin: 30px 0\">
                                        <tr>
                                        <td style=\"font-weight:bold;width:30%;border-top: 2px solid #ff6600\">Discipline:</td>
                                        <td style=\"border-top: 2px solid #ff6600\">$Discipline</td></tr>
                                        <tr><td style=\"font-weight:bold;\">Naam verwijzer:</td>
                                        <td>$Naam_verwijzer</td></tr>
                                        <tr>
                                        <td style=\"font-weight:bold;\">E-mail verwijzer:</td>
                                        <td>$Email_verwijzer</td>
                                        </tr>
                                        <tr>
                                        <td style=\"font-weight:bold;\">Telefoon verwijzer:</td>
                                        <td>$Tel_verwijzer</td>
                                        </tr>
                                        <tr>
                                        <td style=\"font-weight:bold; border-top: 2px solid #ff6600\">Naam pati&euml;nt:</td>
                                        <td style=\"border-top: 2px solid #ff6600\">$Naam_patient</td>
                                        </tr>
                                        <tr>
                                        <td style=\"font-weight:bold;\">E-mail pati&euml;nt:</td>
                                        <td>$Email_patient</td>
                                        </tr>
                                        <tr>
                                        <td style=\"font-weight:bold;\">Telefoon pati&euml;nt:</td>
                                        <td>$Tel_patient</td>
                                        </tr>
                                        <tr>
                                        <td style=\"font-weight:bold;\">BSN:</td>
                                        <td>$BSN</td>
                                        </tr>
                                        <tr>
                                        <td style=\"font-weight:bold; border-top: 2px solid #ff6600\">PARODONTAAL:</td>
                                        <td style=\"border-top: 2px solid #ff6600\">$Parodontaal</td>
                                        </tr>
                                        <tr>
                                        <td style=\"font-weight:bold\">Anders, nl:</td>
                                        <td>$Paro_anders</td>
                                        </tr>
                                        <tr>
                                        <td style=\"font-weight:bold;\">Extracties:</td>
                                        <td>$Extracties</td>
                                        </tr>
                                        <tr>
                                        <td style=\"font-weight:bold;\">Elementen:</td>
                                        <td>$Elementen</td>
                                        </tr>
                                        <tr>
                                        <td style=\"font-weight:bold;\">Voorbehandeld:</td>
                                        <td>$Voorbehandeld</td>
                                        </tr>
                                        <tr>
                                        <td style=\"font-weight:bold;\">Voorbehandeling:</td>
                                        <td>$Voorbehandeling</td>
                                        </tr>
                                        <tr>
                                        <td style=\"font-weight:bold;\">Nazorg:</td>
                                        <td>$Nazorg</td>
                                        </tr>
                                        <tr>
                                        <td style=\"font-weight:bold;\">Premedicatie:</td>
                                        <td>$Premedicatie</td>
                                        </tr>
                                        <tr>
                                        <td style=\"font-weight:bold;\">Antibioticum:</td>
                                        <td>$Antibioticum</td>
                                        </tr>
                                        <tr>
                                        <td style=\"font-weight:bold;\">Nazorg door wie:</td>
                                        <td>$Nazorg_doorwie</td>
                                        </tr>
                                        <tr>
                                        <td style=\"font-weight:bold;border-top: 2px solid #ff8800\"\">IMPLANTOLOGISCH:</td>
                                        <td style=\"border-top: 2px solid #ff8800\">$Implantologisch</td>
                                        </tr>
                                        <tr>
                                        <td style=\"font-weight:bold;\">Anders, nl:</td>
                                        <td>$Impl_anders</td>
                                        </tr>
                                        <tr>
                                        <td style=\"font-weight:bold;\">Suprastructuur:</td>
                                        <td>$Suprastructuur</td>
                                        </tr>
                                        <tr>
                                        <td style=\"font-weight:bold;border-top: 2px solid #ff8800\">COSMETISCH:</td>
                                        <td style=\"border-top: 2px solid #ff8800\">$Cosmetisch</td>
                                        </tr>
                                        <tr>
                                        <tr>
                                        <td style=\"font-weight:bold\">Anders, nl:</td>
                                        <td>$Cosm_anders</td>
                                        </tr>
                                        <tr>
                                        <td style=\"font-weight:bold;\">Restauratieve planning:</td>
                                        <td>$Planning</td>
                                        </tr>
                                        <tr>
                                        <td style=\"font-weight:bold;\">Bijlages:</td>
                                        <td>$files</td>
                                        </tr>
                                            
                                    </table>
                                </body>
                                </html>
                            "
;
  
        mail($to, $subject, $message, $headers);

        mail($Email_verwijzer,"Verwijzing parodontoloog ontvangen","

                    
<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"    \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">


<html>


<head>
                        
<title>E-mail verzonden</title>

<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">

</head>
                        
<body>

<p>Beste $Naam_verwijzer,</p>

<p>Uw verwijzing is in goede orde ontvangen.</p>
                        
<p>Onze praktijk neemt spoedig contact op met de pati&euml;nt om een afspraak te maken. Na het eerste onderzoek ontvangt u een uitgebreid consultverslag van de parodontiumstatus en de daarbij gemaakte r&ouml;ntgenfoto's per email of per post.</p>
                
<p>Met vriendelijke groet,</p>

<p>Laura Ziukaite, parodontoloog,<br>
Tandarts aan het IJ
</p>

</body>

</html>

                        "

            
                       ,$headers);

    header("Location: bedankt.php");
    }
else {
        // error string initaliseren
        $strError = '<div class="formerror"><p>Controleer alstublieft de volgende velden en probeer opnieuw:</p><ul>';
        // alle errors toevoegen
        foreach ($arrErrors as $error) {
            $strError .= "<li>$error</li>";
        }

        // error string afsluiten
        $strError .= '</ul></div>';
    }
}

?>


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
<?php
/**
* Multi file upload example
* @author Resalat Haque
* @link http://www.w3bees.com/2013/02/multiple-file-upload-with-php.html
**/


$valid_formats = array("jpg", "png", "gif", "zip");
$max_file_size = 1024*1000; //1000 kb
$path = "uploads/"; // Upload directory
$count = 0;
$your_email = '[email protected]';//<<--  update this to your email address
// explode all lines



if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST"){
    // Loop $_FILES to execute all files
    foreach ($_FILES['files']['name'] as $f => $name) {    
        if ($_FILES['files']['error'][$f] == 4) {
            continue; // Skip file if any error found
        }          
        if ($_FILES['files']['error'][$f] == 0) {              
            if ($_FILES['files']['size'][$f] > $max_file_size) {
                $message[] = "$name is te groot!.";
                continue; // Skip large files
            }
            elseif( ! in_array(pathinfo($name, PATHINFO_EXTENSION), $valid_formats) ){
                $message[] = "$name is geen geldig formaat";
                continue; // Skip invalid file formats
            }
            
            else{ // No error found! Move uploaded files
                $ext = pathinfo($_FILES['files']['name'][$f], PATHINFO_EXTENSION);
                $uniq_name = uniqid() . '.' .$ext;
                if(move_uploaded_file($_FILES["files"]["tmp_name"][$f], $path.$uniq_name)) {
                    $count++; // Number of successfully uploaded files
                    $from = $your_email;
                  

                }
            }
        }
    }
}

?>


en hier het form element:
<form action="#verwijzen" method="post" enctype="multipart/form-data">

Dat laaste werkt geweldig, alleen wat ik al zei, het komt keurig aan i het mapje maar hoe je dit in de mail krijgt...
Kan jij iets hiermee...?
Groetjes, Mary



Toevoeging op 31/05/2016 18:30:49:

ja, die google recaptcha key is nog de test key ;-)
 
- Ariën  -
Beheerder

- Ariën -

31/05/2016 18:34:19
Quote Anchor link
Als het goed is bevat de $_FILES['files'] array een array met daarin de URL's van de geuploadde bestanden.
Die kan je tijdens het mailproces met een foreach() uitlezen, waarna je dan in die lus steeds AddAttachment() met de verwijzing naar het geuploadde bestande uitvoert.

En verder was ik benieuw wat je precies wilt doen met regel 39 t/m 63. Die $_POST-variabelen hoef je niet opnieuw te kopiëren naar nieuwe variabelen. Je kan prima je $_POST['.....'] variabelen gebruiken.
 
Mary Grooteman

Mary Grooteman

31/05/2016 18:49:11
Quote Anchor link
Hoi Arien,
Ik dacht dat die regels 39 t/m 63 nodig waren voor de resultaten van de mail met resultaten, niet dus?
Kijk, de reden waarom ik dit bij beginner heb gepost, wat bedoel je met:

"Die kan je tijdens het mailproces met een foreach() uitlezen, waarna je dan in die lus steeds AddAttachment() met de verwijzing naar het geuploade bestanden uitvoert."

Daar zit voor mij de moeilijkheid, zeg maar een totale blinde vlek...ik heb echt les nodig daarin...
heb je een goed idee? Over die die lus met addAttachment?

Toevoeging op 01/06/2016 08:31:10:

Dus in plaats van
$Tel_verwijzer = $_POST['Tel_verwijzer'];
$Tel_verwijzer = $_POST['....'];

Ik heb geprobeerd
$_POST['Tel_verwijzer'];
maar dan komen er (zoals jij natuurlijk allang weet) geen resultaten meer binnen, dus dat was geen goed idee.
Ik ga zodra ik tijd heb me verdiepen in de AddAttachment()-lus....
 



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.