Class mail probleem...

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

Olivier Peeters

Olivier Peeters

06/01/2012 22:51:03
Quote Anchor link
Hallo iedereen,

ik ben zo goed als klaar met een mailsysteem vanop mijn site. Eerst testte ik hem apart er er ging niks aan. Nu ik hem echter include vanop een andere php pagina (testenvanfunctie1.php) krijg ik wel een foutmelding:

Fatal error: Cannot redeclare class mail in /home/u943035619/public_html/Mailsysteem_ZWAT/Mailtesten/mailsturen1.php on line 24


De code die ik gebruik is:
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
<?php





$file1
='./Downloads/'.$name_of_uploaded_file;
$head = array(
       'to'      =>array($row[Email1] => $row[Voornaam].$row[Naam]  , $row[Email2] => $row[Voornaam].$row[Naam]),
       'from'    =>array('olivier-zwat@hotmail.be' => 'ZWAT Jeugdcomité'),
       'cc'      =>array(''=>''),
//       'bcc'     =>array('olivier-zwat@hotmail.be'=>'ZWAT Jeugdcomite'),
       );
$subject = $_POST["subject"];
$body = $_POST["message"];
$files = array($file1,$file2);

mail::send($head, $subject ,$body, $files);
// mail::send($head,$subj,$body);//$files are optional param


// Hieronder dus niks, maar dan ook niks wijzigen!!!


class mail {
 static $mimetypes=array();

  public static function send($head, $subject, $body, $attachments=array())
  {

    if (count($head['from'])!=1) return false;
    if (count($head['to'  ])==0) return false;
  

    $to='';
    foreach($head['to'] as $cc_addr=>$cc_name)
        $to.= $cc_name . "<" . $cc_addr . ">";
    $fromaddress = array_pop( array_keys  ($head['from']) );
    $fromname    = array_pop( array_values($head['from']) );
    $eol="\r\n";
    $mime_boundary=md5(time())."-2";
    $mime_boundary2= $mime_boundary."-3";

    # Common Headers
    $headers='';
    $headers .= "Message-ID: <".time()."-".$fromaddress.">".$eol;
    $headers .= "Date: ".date('r').$eol;
    $headers .= "From: ".$fromname."<".$fromaddress.">".$eol;
    if (isset($head['cc']))
        foreach($head['cc'] as $cc_address=>$cc_name)
            $headers .= "Cc: ".$cc_name."<".$cc_address.">".$eol;
    if (isset($head['bcc']))
        foreach($head['bcc'] as $cc_address=>$cc_name)
            $headers .= "Bcc: ".$cc_name."<".$cc_address.">".$eol;
    $headers .= "Reply-To: ".$fromname."<".$fromaddress.">".$eol;
    $headers .= "Return-Path: ".$fromname."<".$fromaddress.">".$eol;    // these two to set reply address
    $headers .= "Message-ID: <".time()."-".$fromaddress.">".$eol;
    $headers .= "X-Mailer: PHP v".phpversion().$eol;          // These two to help avoid spam-filters

    # Boundry for marking the split & Multitype Headers

    $headers .= 'Mime-Version: 1.0'.$eol;
    $headers .= "Content-Type: multipart/mixed; boundary=\"".$mime_boundary."\"".$eol.$eol;
    #$headers .= "To: ".$to.$eol;
    #$headers .= "Subject: ".$subject.$eol.$eol;

    $headers .= "This is a MIME-formatted message.  If you see this text it means that your".$eol;
    $headers .= "E-mail software does not support MIME-formatted messages.".$eol.$eol;

    # Open the first part of the mail
    $msg ='';

    $msg .= "--".$mime_boundary.$eol;
    $msg .= "Content-Type: multipart/alternative; boundary=\"$mime_boundary2\"".$eol.$eol;
   $msg .= "This is a MIME-formatted message.  IF you see this text it means that your".$eol;
    $msg .= "E-mail softare does not support MIME-formatted messages.".$eol.$eol;
    $msg .= "--".$mime_boundary2.$eol;
    $msg .= "Content-Type: text/plain; charset=iso-8859-1; format=flowed".$eol;
    $msg .= "Content-Transfer-Encoding: 7bit".$eol;
    $msg .= "Content-Disposition: inline".$eol.$eol;
    $msg .= strip_tags(str_replace("<br>", "\n", $body ));
    $msg .= $eol.$eol;
    $msg .= "--".$mime_boundary2.$eol;
    $msg .= "Content-Type: text/html; charset=iso-8859-1;".$eol;
    $msg .= "Content-Transfer-Encoding: quoted-printable".$eol;
    $msg .= "Content-Disposition: inline".$eol.$eol;
    $msg .= "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">".$eol;
    $msg .= "<html>".$eol;
    $msg .= "<body>".$eol;
    $msg .= mail::mime_html_encode($body).$eol;
    $msg .= "</body>".$eol;
    $msg .= "</html>".$eol;
    $msg .= $eol.$eol;
    $msg .= "--".$mime_boundary2."--".$eol.$eol;


    for($i=0; $i < count($attachments); $i++)
    {

        if (is_file($attachments[$i]))
        {
  
          # File for Attachment
          $file_name = basename($attachments[$i]);
        
          $handle=fopen($attachments[$i], 'rb');
          $f_contents=fread($handle, filesize($attachments[$i]));
          $f_contents=chunk_split(base64_encode($f_contents));    //Encode The Data For Transition using base64_encode();
          $f_type=filetype($attachments[$i]);
          fclose($handle);

          $mime_type = mail::get_mimetype( array_pop( explode(".", $attachments[$i] ) ) );
        
          # Attachment
          $msg .= "--".$mime_boundary.$eol;
          $msg .= "Content-Type: ".$mime_type."; name=\"".$file_name."\"".$eol;
          $msg .= "Content-Transfer-Encoding: base64".$eol;
          $msg .= "Content-Description: inline; $eol filename=\"".$file_name."\"".$eol.$eol; // !! This line needs TWO end of lines !! IMPORTANT !!
          $msg .= $f_contents.$eol.$eol;
        }
    }

  

    # Finished
    $msg .= "--".$mime_boundary."--".$eol.$eol;  // finish with two eol's for better security. see Injection.
  
    # SEND THE EMAIL

    ini_set('sendmail_from',$fromaddress);  // the INI lines are to force the From Address to be used !
    $mail_sent = mail($to, $subject, $msg, $headers);
  
//    ini_restore('sendmail_from');
       return $mail_sent;
  }



  public static function get_mimetype($ext)
  {

    if (count(mail::$mimetypes)==0)
        mail::$mimetypes = mail::mimelist();
    $ext_lower = strtolower(str_replace(".","",$ext));
    if (isset( mail::$mimetypes[$ext_lower] ))
        return mail::$mimetypes[$ext_lower];

    return "application/octet-stream";
  }



  private static function mimelist()
  {

    $arr['323'  ]='text/h323';
    $arr['acx'  ]='application/internet-property-stream';
    $arr['ai'   ]='application/postscript';
    $arr['aif'  ]='audio/x-aiff';
    $arr['aifc' ]='audio/x-aiff';
    $arr['aiff' ]='audio/x-aiff';
    $arr['asf'  ]='video/x-ms-asf';
    $arr['asr'  ]='video/x-ms-asf';
    $arr['asx'  ]='video/x-ms-asf';
    $arr['au'   ]='audio/basic';
    $arr['avi'  ]='video/x-msvideo';
    $arr['axs'  ]='application/olescript';
    $arr['bas'  ]='text/plain';
    $arr['bcpio']='application/x-bcpio';
    $arr['bin'  ]='application/octet-stream';
    $arr['bmp'  ]='image/bmp';
    $arr['c'    ]='text/plain';
    $arr['cat'  ]='application/vnd.ms-pkiseccat';
    $arr['cdf'  ]='application/x-cdf';
    $arr['cer'  ]='application/x-x509-ca-cert';
    $arr['class']='application/octet-stream';
    $arr['clp'  ]='application/x-msclip';
    $arr['cmx'  ]='image/x-cmx';
    $arr['cod'  ]='image/cis-cod';
    $arr['cpio' ]='application/x-cpio';
    $arr['crd'  ]='application/x-mscardfile';
    $arr['crl'  ]='application/pkix-crl';
    $arr['crt'  ]='application/x-x509-ca-cert';
    $arr['csh'  ]='application/x-csh';
    $arr['css'  ]='text/css';
    $arr['dcr'  ]='application/x-director';
    $arr['der'  ]='application/x-x509-ca-cert';
    $arr['dir'  ]='application/x-director';
    $arr['dll'  ]='application/x-msdownload';
    $arr['dms'  ]='application/octet-stream';
    $arr['doc'  ]='application/msword';
    $arr['docx' ]='application/msword';
    $arr['dot'  ]='application/msword';
    $arr['dvi'  ]='application/x-dvi';
    $arr['dxr'  ]='application/x-director';
    $arr['eps'  ]='application/postscript';
    $arr['etx'  ]='text/x-setext';
    $arr['evy'  ]='application/envoy';
    $arr['exe'  ]='application/octet-stream';
    $arr['fif'  ]='application/fractals';
    $arr['flr'  ]='x-world/x-vrml';
    $arr['gif'  ]='image/gif';
    $arr['gtar' ]='application/x-gtar';
    $arr['gz'   ]='application/x-gzip';
    $arr['h'    ]='text/plain';
    $arr['hdf'  ]='application/x-hdf';
    $arr['hlp'  ]='application/winhlp';
    $arr['hqx'  ]='application/mac-binhex40';
    $arr['hta'  ]='application/hta';
    $arr['htc'  ]='text/x-component';
    $arr['htm'  ]='text/html';
    $arr['html' ]='text/html';
    $arr['htt'  ]='text/webviewhtml';
    $arr['ico'  ]='image/x-icon';
    $arr['ief'  ]='image/ief';
    $arr['iii'  ]='application/x-iphone';
    $arr['ins'  ]='application/x-internet-signup';
    $arr['isp'  ]='application/x-internet-signup';
    $arr['jfif' ]='image/pipeg';
    $arr['jpe'  ]='image/jpeg';
    $arr['jpeg' ]='image/jpeg';
    $arr['jpg'  ]='image/jpeg';
    $arr['js'   ]='application/x-javascript';
    $arr['latex']='application/x-latex';
    $arr['lha'  ]='application/octet-stream';
    $arr['lsf'  ]='video/x-la-asf';
    $arr['lsx'  ]='video/x-la-asf';
    $arr['lzh'  ]='application/octet-stream';
    $arr['m13'  ]='application/x-msmediaview';
    $arr['m14'  ]='application/x-msmediaview';
    $arr['m3u'  ]='audio/x-mpegurl';
    $arr['man'  ]='application/x-troff-man';
    $arr['mdb'  ]='application/x-msaccess';
    $arr['me'   ]='application/x-troff-me';
    $arr['mht'  ]='message/rfc822';
    $arr['mhtml']='message/rfc822';
    $arr['mid'  ]='audio/mid';
    $arr['mny'  ]='application/x-msmoney';
    $arr['mov'  ]='video/quicktime';
    $arr['movie']='video/x-sgi-movie';
    $arr['mp2'  ]='video/mpeg';
    $arr['mp3'  ]='audio/mpeg';
    $arr['mpa'  ]='video/mpeg';
    $arr['mpe'  ]='video/mpeg';
    $arr['mpeg' ]='video/mpeg';
    $arr['mpg'  ]='video/mpeg';
    $arr['mpp'  ]='application/vnd.ms-project';
    $arr['mpv2' ]='video/mpeg';
    $arr['ms'   ]='application/x-troff-ms';
    $arr['mvb'  ]='application/x-msmediaview';
    $arr['nws'  ]='message/rfc822';
    $arr['oda'  ]='application/oda';
    $arr['p10'  ]='application/pkcs10';
    $arr['p12'  ]='application/x-pkcs12';
    $arr['p7b'  ]='application/x-pkcs7-certificates';
    $arr['p7c'  ]='application/x-pkcs7-mime';
    $arr['p7m'  ]='application/x-pkcs7-mime';
    $arr['p7r'  ]='application/x-pkcs7-certreqresp';
    $arr['p7s'  ]='application/x-pkcs7-signature';
    $arr['pbm'  ]='image/x-portable-bitmap';
    $arr['pdf'  ]='application/pdf';
    $arr['pfx'  ]='application/x-pkcs12';
    $arr['pgm'  ]='image/x-portable-graymap';
    $arr['pko'  ]='application/ynd.ms-pkipko';
    $arr['pma'  ]='application/x-perfmon';
    $arr['pmc'  ]='application/x-perfmon';
    $arr['pml'  ]='application/x-perfmon';
    $arr['pmr'  ]='application/x-perfmon';
    $arr['pmw'  ]='application/x-perfmon';
    $arr['pnm'  ]='image/x-portable-anymap';
    $arr['pot'  ]='application/vnd.ms-powerpoint';
    $arr['ppm'  ]='image/x-portable-pixmap';
    $arr['pps'  ]='application/vnd.ms-powerpoint';
    $arr['ppt'  ]='application/vnd.ms-powerpoint';
    $arr['pptx' ]='application/vnd.ms-powerpoint';
    $arr['prf'  ]='application/pics-rules';
    $arr['ps'   ]='application/postscript';
    $arr['pub'  ]='application/x-mspublisher';
    $arr['qt'   ]='video/quicktime';
    $arr['ra'   ]='audio/x-pn-realaudio';
    $arr['ram'  ]='audio/x-pn-realaudio';
    $arr['ras'  ]='image/x-cmu-raster';
    $arr['rgb'  ]='image/x-rgb';
    $arr['rmi'  ]='audio/mid';
    $arr['roff' ]='application/x-troff';
    $arr['rtf'  ]='application/rtf';
    $arr['rtx'  ]='text/richtext';
    $arr['scd'  ]='application/x-msschedule';
    $arr['sct'  ]='text/scriptlet';
    $arr['sh'   ]='application/x-sh';
    $arr['shar' ]='application/x-shar';
    $arr['sit'  ]='application/x-stuffit';
    $arr['snd'  ]='audio/basic';
    $arr['spc'  ]='application/x-pkcs7-certificates';
    $arr['spl'  ]='application/futuresplash';
    $arr['src'  ]='application/x-wais-source';
    $arr['sst'  ]='application/vnd.ms-pkicertstore';
    $arr['stl'  ]='application/vnd.ms-pkistl';
    $arr['stm'  ]='text/html';
    $arr['svg'  ]='image/svg+xml';
    $arr['swf'  ]='application/x-shockwave-flash';
    $arr['t'    ]='application/x-troff';
    $arr['tar'  ]='application/x-tar';
    $arr['tcl'  ]='application/x-tcl';
    $arr['tex'  ]='application/x-tex';
    $arr['texi' ]='application/x-texinfo';
    $arr['tgz'  ]='application/x-compressed';
    $arr['tif'  ]='image/tiff';
    $arr['tiff' ]='image/tiff';
    $arr['tr'   ]='application/x-troff';
    $arr['trm'  ]='application/x-msterminal';
    $arr['tsv'  ]='text/tab-separated-values';
    $arr['txt'  ]='text/plain';
    $arr['uls'  ]='text/iuls';
    $arr['ustar']='application/x-ustar';
    $arr['vcf'  ]='text/x-vcard';
    $arr['vrml' ]='x-world/x-vrml';
    $arr['wav'  ]='audio/x-wav';
    $arr['wcm'  ]='application/vnd.ms-works';
    $arr['wdb'  ]='application/vnd.ms-works';
    $arr['wks'  ]='application/vnd.ms-works';
    $arr['wmf'  ]='application/x-msmetafile';
    $arr['wps'  ]='application/vnd.ms-works';
    $arr['wri'  ]='application/x-mswrite';
    $arr['wrl'  ]='x-world/x-vrml';
    $arr['wrz'  ]='x-world/x-vrml';
    $arr['xaf'  ]='x-world/x-vrml';
    $arr['xbm'  ]='image/x-xbitmap';
    $arr['xla'  ]='application/vnd.ms-excel';
    $arr['xlc'  ]='application/vnd.ms-excel';
    $arr['xlm'  ]='application/vnd.ms-excel';
    $arr['xls'  ]='application/vnd.ms-excel';
    $arr['xlsx' ]='application/vnd.ms-excel';
    $arr['xlt'  ]='application/vnd.ms-excel';
    $arr['xlw'  ]='application/vnd.ms-excel';
    $arr['xof'  ]='x-world/x-vrml';
    $arr['xpm'  ]='image/x-xpixmap';
    $arr['xwd'  ]='image/x-xwindowdump';
    $arr['z'    ]='application/x-compress';
    $arr['zip'  ]='application/zip';
    return $arr;
  }


  private function mime_html_encode($input , $line_max = 76)
  {

  
    $eol    = "\r\n";//MAIL_MIMEPART_CRLF
    $output = '';
    $line   = '';
    $intag  = false;
  
  
    for($i=0; $i<strlen($input); $i++)
    {

      $ip=$input{$i};
      $op='';
        
      if ($intag)
      {

          if ($ip=="=") $op="=3D";
          else $op= $ip;
      }

      else
      {
          if ($ip=="\"") $op='"';//'
          else if ($ip=="&") $op="&";
          else if ($ip=="'") $op="'";
          else $op= $ip;
      }



      if ((strlen($line)+strlen($op))>=$line_max)
      {

          $output.=$line.'='.$eol;
          //if ($intag) $output.=$line.'='.$eol;
          //else  $output.=$line.$eol;

          $line='';
      }

      $line.=$op;

      if($ip=='<')
          $intag=true;
      else if ($ip=='>')
          $intag=false;
    }

    return $output.$line.$eol;
  }
}

?>


Wie kan helpen?

Vriendelijke groeten,
Olivier Peeters
Gewijzigd op 06/01/2012 22:53:13 door Olivier Peeters
 
PHP hulp

PHP hulp

06/12/2022 00:33:31
 
- Ariën  -
Beheerder

- Ariën -

06/01/2012 23:03:45
Quote Anchor link
Je roept je class twee keer aan?
 
Olivier Peeters

Olivier Peeters

06/01/2012 23:05:31
Quote Anchor link
Ik include de pagina 3 maal op deze site, ik verzend dan ook 3 verschillende mails. Is dat het probleem dan?

Groeten,
Olivier
 
- Ariën  -
Beheerder

- Ariën -

06/01/2012 23:22:45
Quote Anchor link
Grootswaarschijnlijk wel.
 
Olivier Peeters

Olivier Peeters

06/01/2012 23:24:31
Quote Anchor link
En hoe kan ik dit dan oplossen en drie verschillende mails tegelijk versturen?

Groeten
 
- Ariën  -
Beheerder

- Ariën -

06/01/2012 23:27:23
Quote Anchor link
Je class maar 1 keer laten includeren.
 
Wouter J

Wouter J

06/01/2012 23:31:00
Quote Anchor link
door require_once of include_once te gebruiken?
 
Olivier Peeters

Olivier Peeters

07/01/2012 11:14:52
Quote Anchor link
Ik heb het geprobeerd, maar ik kom er niet uit, ik blijf tegen dezelfde fout aanlopen.

Dit is de code die ik gebruik om de mailpagina aan te roepen:
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
<?php
//Uitlezen van emailadressen BEN
if($_POST[BEN]=='1') {
    $sqlB = " SELECT * FROM `u943035619_10` WHERE BEN ='1' ";
    $results = $db->query($sqlB);

    // Resultaten van de BEN echo'en
    foreach($results as $row)
    {

        echo 'id = '. $row[id].'<br />';
        echo 'Voornaam = '. $row[Voornaam].'<br />';
        echo 'Naam = '. $row[Naam].'<br />';
        echo 'Emailadres 1 = '. $row[Email1].'<br />';
        echo 'Emailadres 2 = '. $row[Email2].'<br />';
        echo 'Abonnement op benjamins = '. $row[BEN].'<br />';
        echo 'Abonnement op pupillen = '. $row[PUP].'<br />';
        echo 'Abonnement op miniemen = '. $row[MIN].'<br /><br />';
        $id[] = $row[id];
        $mail[] = $row[Email1];
        if (empty($row[Email2])) {
        }
else {
            $mail[] = $row[Email2];
        }

    include 'mailsturen1.php';
    }

    echo '<hr>';
}


//Uitlezen van emailadressen PUP
if($_POST[PUP]=='1') {
    $sqlP = "SELECT * FROM `u943035619_10` WHERE PUP ='1' ";
    $results = $db->query($sqlP);

foreach($results as $row)
{

    if (!empty($id)) {
        if(array_search($row[id],$id) !== false) {
        
            $nr=array_search($row[id],$id);
            // Einde van de array_search
    } else {
    echo 'id = '. $row[id].'<br />';
    echo 'Voornaam = '. $row[Voornaam].'<br />';
    echo 'Naam = '. $row[Naam].'<br />';
    echo 'Emailadres 1 = '. $row[Email1].'<br />';
    echo 'Emailadres 2 = '. $row[Email2].'<br />';
    echo 'Abonnement op benjamins = '. $row[BEN].'<br />';
    echo 'Abonnement op pupillen = '. $row[PUP].'<br />';
    echo 'Abonnement op miniemen = '. $row[MIN].'<br /><br />';
    $id[] = $row[id];
    $mail[] = $row[Email1];
    if (empty($row[Email2])) {  } else { $mail[] = $row[Email2]; }
    include 'mailsturen1.php';
    }
    }
    else {
    // echo"De waarde was niet gevonden in de array";
    echo 'id = '. $row[id].'<br />';
    echo 'Voornaam = '. $row[Voornaam].'<br />';
    echo 'Naam = '. $row[Naam].'<br />';
    echo 'Emailadres 1 = '. $row[Email1].'<br />';
    echo 'Emailadres 2 = '. $row[Email2].'<br />';
    echo 'Abonnement op benjamins = '. $row[BEN].'<br />';
    echo 'Abonnement op pupillen = '. $row[PUP].'<br />';
    echo 'Abonnement op miniemen = '. $row[MIN].'<br /><br />';
    $id[] = $row[id];
    $mail[] = $row[Email1];
    if (empty($row[Email2])) {     } else { $mail[] = $row[Email2]; }
    include 'mailsturen1.php';
    }
    }

echo '<hr>';
}


//Uitlezen van emailadressen MIN
if($_POST[MIN]=='1') {
    $sqlM = "SELECT * FROM `u943035619_10` WHERE MIN ='1' ";
    $results = $db->query($sqlM);

foreach($results as $row)
    {

        if (!empty($id)) {
            if(array_search($row[id],$id) !== false) {
                $nr=array_search($row[id],$id);
                // Einde van de array_search
                } else {
                    echo 'id = '. $row[id].'<br />';
                    echo 'Voornaam = '. $row[Voornaam].'<br />';
                    echo 'Naam = '. $row[Naam].'<br />';
                    echo 'Emailadres 1 = '. $row[Email1].'<br />';
                    echo 'Emailadres 2 = '. $row[Email2].'<br />';
                    echo 'Abonnement op benjamins = '. $row[BEN].'<br />';
                    echo 'Abonnement op pupillen = '. $row[PUP].'<br />';
                    echo 'Abonnement op miniemen = '. $row[MIN].'<br /><br />';
                $id[] = $row[id];
                $mail[] = $row[Email1];
                if (empty($row[Email2])) {    } else { $mail[] = $row[Email2]; }
                include 'mailsturen1.php';
                }
                }
else {
                //    echo"De waarde was niet gevonden in de array";
                echo 'id = '. $row[id].'<br />';
                echo 'Voornaam = '. $row[Voornaam].'<br />';
                echo 'Naam = '. $row[Naam].'<br />';
                echo 'Emailadres 1 = '. $row[Email1].'<br />';
                echo 'Emailadres 2 = '. $row[Email2].'<br />';
                echo 'Abonnement op benjamins = '. $row[BEN].'<br />';
                echo 'Abonnement op pupillen = '. $row[PUP].'<br />';
                echo 'Abonnement op miniemen = '. $row[MIN].'<br /><br />';
                $id[] = $row[id];
                $mail[] = $row[Email1];
                if (empty($row[Email2])) { } else { $mail[] = $row[Email2]; }
                include 'mailsturen1.php';
                }
    }

echo '<hr>';
}

?>


Wat kan ik aanpassen zodat het wel lukt?

Vriendelijke groeten,
Olivier Peeters
Gewijzigd op 07/01/2012 11:20:11 door Olivier Peeters
 
Wouter J

Wouter J

07/01/2012 11:23:03
Quote Anchor link
Je hoeft maar 1 keer mailsturen1.php te includen. En wat je nu doet is hem stoppen in 2 foreach loops, zal hij dan maar 1 keer worden aangeroepen?

Je hoeft het dus maar 1 keer te includen, en dat doe je ergens bovenin je script en dan ben je klaar. Of mocht je dat niet willen, wat me zeer vreemd lijkt, dan kun je wat ik hierboven zei include_once of require_once gebruiken.

Verder fouten:
- Getallen buiten quotes, ook in SQL
- Geen * gebruiken, maar selecteren wat je wilt.
- Je gebruikt allemaal constants? Of wil je strings gebruiken? Strings horen altijd tussen quotes, $_POST['ben'] is totaal wat anders als $_POST[ben]
 
Olivier Peeters

Olivier Peeters

07/01/2012 11:52:00
Quote Anchor link
Hallo Wouter,

ik denk niet dat ik hem maar een keer moet includen... Dat heb ik nu gedaan, op het einde includen en er word geen enkele mail meer verzonden.

Hoe het script werkt is alsvolgt: Ik geef in een formulier in aan wie ik een mail wil versturen (in een ander HTML-bestand).
Daarna haal ik alle emailadressen die ik wil bereiken uit de database. Per emailadres word er een (persoonlijke) email verzonden. (daarom ook die foreach loop en telkens die include => mail zenden erachter)

Hopelijk verduidelijkt dit wat de code? En weten jullie een oplossing, want ik zie het niet...
Die fouten die je aangeeft, zal ik aanpassen.

Groeten,
Olivier
Gewijzigd op 07/01/2012 22:15:26 door Olivier Peeters
 



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.