Kan iemand mij helpen met een email script???

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

31/03/2005 18:32:00
Quote Anchor link
Ik heb op een site een mailfunctie gezet, en daarbij kan je de ontvanger invullen, en van wie het komt.
Daarvoor heb ik 2 bestandjes:

mail.htm en mailer.php

mail. htm ziet er zo uit: <HTML>
<HEAD>
<TITLE></TITLE>
<BODY>
<FORM action=mailer.php method=post enctype="multipart/form-data"><INPUT type=hidden value=http://www.wyger.nl/usr/Florian/12345qwerty.htm name=redirect>
<TABLE id=AutoNumber1 style="BORDER-COLLAPSE: collapse" borderColor=#111111
height=175 cellSpacing=0 cellPadding=0 width="863" border=0>
<TBODY>
<TR>
<TD width="86" height=22>&nbsp;</TD>
<TD width="777" height=22>&nbsp;
</TD></TR>
<TR>
<TD width="86" height=22>Ontvanger:</TD>
<TD width="777" height=22>
<P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px">
<INPUT
name=ontvanger size="20"></P></TD></TR>
<TR>
<TD height=22><p>E-mail adres:</p></TD>
<TD height=22>
<P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px">
<INPUT
name=email size="20">
</P></TD>
</TR>
<TR>
<TD width="86" height=22><p>BCC:</p> </TD>
<TD width="777" height=22>
<P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px">
<INPUT
name=bccmail id="bccmail" size="20"></P></TD></TR>
<TR>
<TD height=22 width="86">
<P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px">Onderwerp:</P></TD>
<TD height=22 width="777">
<P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px">
<INPUT
name=subject size="20"></P></TD>
</TR>

<TR>
<TD height=22 width="86">
<P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px">Bijlage 1:</P></TD>
<TD height=22 width="777">
<P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px">
<input type="file" name="bestand1" size="20"></P></TD>
</TR>
<TR>
<TD width="86" height=22>
<P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px">Bijlage 2:</P></TD>
<TD width="777" height=22>
<P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px">
<input type="file" name="bestand2" size="20"></P></TD></TR>
<TR>
<TD width="86" height=21>
<P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px">Tekst:</P></TD>
<TD width="777" height=21>
<P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px">
<TEXTAREA name=text rows=9 cols=91></TEXTAREA></P></TD></TR></TBODY></TABLE>
<P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px"><INPUT type=submit value=Verzend name=submit><BR><BR></P></FORM>
</BODY></HTML>

mailer.php zo:

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
<?

$recipient
= "$ontvanger";

// bcc emails (separate multiples with commas (,))
$bcc = "";

$referers = array ($_SERVER["HTTP_HOST"]);

$banlist = array ('');

define("SEPARATOR", ($separator)?$separator:": ");

define("NEWLINE", ($newline)?$newline:"\n");

define("VERSION", "5.0");


function
print_error($reason,$type = 0) {
   build_body($title, $bgcolor, $text_color, $link_color, $vlink_color, $alink_color, $style_sheet);
   if ($type == "missing") {
      if ($missing_field_redirect) {
         header("Location: $missing_field_redirect?error=$reason");
         exit;
      }
else {
      ?>

Het formulier is niet verzonden om de volgende redenen:<p>
<ul>
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
<?
      echo $reason."\n";
      ?>
</ul>
Gebruik de terug-knop in je browser om terug te gaan.
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
<?
      }
   }
else { // every other error
      ?>

Het formulier is niet verzonden om de volgende redenen:<p>
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
<?
   }
   echo "<br><br>\n";
   exit;
}


function
check_banlist($banlist, $email) {
   if (count($banlist)) {
      $allow = true;
      foreach($banlist as $banned) {
         $temp = explode("@", $banned);
         if ($temp[0] == "*") {
            $temp2 = explode("@", $email);
            if (trim(strtolower($temp2[1])) == trim(strtolower($temp[1])))
               $allow = false;
         }
else {
            if (trim(strtolower($email)) == trim(strtolower($banned)))
               $allow = false;
         }
      }
   }

   if (!$allow) {
      print_error("Je gebruikt een door de Master-Hackers geblokkeerd e-mail adres... Probeer een andere.");
   }
}

function
check_referer($referers) {
   if (count($referers)) {
      $found = false;

      $temp = explode("/",getenv("HTTP_REFERER"));
      $referer = $temp[2];
      
      if ($referer=="") {$referer = $_SERVER['HTTP_REFERER'];
         list($remove,$stuff)=split('//',$referer,2);
         list($home,$stuff)=split('/',$stuff,2);
         $referer = $home;
      }

      
      for ($x=0; $x < count($referers); $x++) {
         if (eregi ($referers[$x], $referer)) {
            $found = true;
         }
      }

      if ($referer =="")
         $found = false;
      if (!$found){
         print_error("Je komt van een verkeerde site.");
         error_log("[FormMail.php] Illegale kopie. (".getenv("HTTP_REFERER").")", 0);
      }

         return $found;
      }
else {
         return true;
   }
}

if ($referers)
   check_referer($referers);

if ($banlist)
   check_banlist($banlist, $email);

function
parse_form($array, $sort = "") {
   // build reserved keyword array
   $reserved_keys[] = "MAX_FILE_SIZE";
   $reserved_keys[] = "required";
   $reserved_keys[] = "redirect";
   $reserved_keys[] = "require";
   $reserved_keys[] = "path_to_file";
   $reserved_keys[] = "recipient";
   $reserved_keys[] = "subject";
   $reserved_keys[] = "sort";
   $reserved_keys[] = "style_sheet";
   $reserved_keys[] = "bgcolor";
   $reserved_keys[] = "text_color";
   $reserved_keys[] = "link_color";
   $reserved_keys[] = "vlink_color";
   $reserved_keys[] = "alink_color";
   $reserved_keys[] = "title";
   $reserved_keys[] = "missing_fields_redirect";
   $reserved_keys[] = "env_report";
   $reserved_keys[] = "submit";
   if (count($array)) {
      if (is_array($sort)) {
         foreach ($sort as $field) {
            $reserved_violation = 0;
            for ($ri=0; $ri<count($reserved_keys); $ri++)
               if ($array[$field] == $reserved_keys[$ri]) $reserved_violation = 1;

            if ($reserved_violation != 1) {
               if (is_array($array[$field])) {
                  for ($z=0;$z<count($array[$field]);$z++)
                     $content .= $field.SEPARATOR.$array[$field][$z].NEWLINE;
               }
else
                  $content .= $field.SEPARATOR.$array[$field].NEWLINE;
            }
         }
      }

      while (list($key, $val) = each($array)) {
         $reserved_violation = 0;
         for ($ri=0; $ri<count($reserved_keys); $ri++)
            if ($key == $reserved_keys[$ri]) $reserved_violation = 1;

         for ($ri=0; $ri<count($sort); $ri++)
            if ($key == $sort[$ri]) $reserved_violation = 1;

         // prepare content
         if ($reserved_violation != 1) {
            if (is_array($val)) {
               for ($z=0;$z<count($val);$z++)
                  $content .= $key.SEPARATOR.$val[$z].NEWLINE;
            }
else
               $content .= $key.SEPARATOR.$val.NEWLINE;
         }
      }
   }

   return $content;
}

function
mail_it($content, $subject, $email, $recipient) {
   global $bcc;

    $headers .= "From:" . $email . "\n";
  if ($bcc) $headers .= "Bcc: ".$bcc."\n";
    $headers .= "X-Mailer: PHP\n"; // mailer
    $headers .= "Return-Path:" . $email . "\n";
  
   mail($recipient, $subject, $content, $headers);
}

function
build_body($title, $bgcolor, $text_color, $link_color, $vlink_color, $alink_color, $style_sheet) {
   if ($style_sheet)
      echo "<LINK rel=STYLESHEET href=\"$style_sheet\" Type=\"text/css\">\n";
   if ($title)
      echo "<title>$title</title>\n";
   if (!$bgcolor)
      $bgcolor = "#FFFFFF";
   if (!$text_color)
      $text_color = "#000000";
   if (!$link_color)
      $link_color = "#0000FF";
   if (!$vlink_color)
      $vlink_color = "#FF0000";
   if (!$alink_color)
      $alink_color = "#000088";
   if ($background)
      $background = "background=\"$background\"";
   echo "<body bgcolor=\"$bgcolor\" text=\"$text_color\" link=\"$link_color\" vlink=\"$vlink_color\" alink=\"$alink_color\" $background>\n\n";
}



$recipient_in = split(',',$recipient);
for ($i=0;$i<count($recipient_in);$i++) {
   $recipient_to_test = trim($recipient_in[$i]);
   if (!eregi("^[_\\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\\.)+[a-z]{2,6}$", $recipient_to_test)) {
      print_error("<b>FOUT E-MAIL ADRES!($recipient_to_test)</b>");
   }
}



if ($required)
   $require = $required;
if ($require) {
   $require = ereg_replace( " +", "", $require);
   $required = split(",",$require);
   for ($i=0;$i<count($required);$i++) {
      $string = trim($required[$i]);
      if((!(${$string})) || (!(${$string}))) {
         if ($missing_fields_redirect) {
            header ("Locatie: $missing_fields_redirect");
            exit;
         }

         $require;
         $missing_field_list .= "<b>Ik mis: $required[$i]</b><br>\n";
      }
   }

   if ($missing_field_list)
      print_error($missing_field_list,"missing");
}


if (($email) || ($EMAIL)) {
   $email = trim($email);
   if ($EMAIL) $email = trim($EMAIL);
   if (!eregi("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,6}$", $email))
      print_error("Je <b>email address</b> is ongeldig");
   $EMAIL = $email;
}


if (($ZIP_CODE) || ($zip_code)) {
   $zip_code = trim($zip_code);
   if ($ZIP_CODE) $zip_code = trim($ZIP_CODE);
   if (!ereg("(^[0-9]{5})-([0-9]{4}$)", trim($zip_code)) && (!ereg("^[a-zA-Z][0-9][a-zA-Z][[:space:]][0-9][a-zA-Z][0-9]$", trim($zip_code))) && (!ereg("(^[0-9]{5})", trim($zip_code))))
      print_error("Je <b>postcode</b> is ongeldig");
}


if (($PHONE_NO) || ($phone_no)) {
   $phone_no = trim($phone_no);
   if ($PHONE_NO) $phone_no = trim($PHONE_NO);
   if (!ereg("(^(.*)[0-9]{3})(.*)([0-9]{3})(.*)([0-9]{4}$)", $phone_no))
      print_error("your <b>phone number</b> is invalid");
}


if (($FAX_NO) || ($fax_no)) {
   $fax_no = trim($fax_no);
   if ($FAX_NO) $fax_no = trim($FAX_NO);
   if (!ereg("(^(.*)[0-9]{3})(.*)([0-9]{3})(.*)([0-9]{4}$)", $fax_no))
      print_error("your <b>fax number</b> is invalid");
}


if ($sort == "alphabetic") {
   uksort($HTTP_POST_VARS, "strnatcasecmp");
}
elseif ((ereg('^order:.*,.*', $sort)) && ($list = explode(',', ereg_replace('^order:', '', $sort)))) {
   $sort = $list;
}


$content = parse_form($HTTP_POST_VARS, $sort);

if ($attachment_name) {
   if ($attachment_size > 0) {
      if (!$attachment_type) $attachment_type =  "application/unknown";
      $content .= "Attached File: ".$bestand1."\n";
      $fp = fopen($attachment,  "r");
      $attachment_chunk = fread($fp, filesize($attachment));
      $attachment_chunk = base64_encode($attachment_chunk);
      $attachment_chunk = chunk_split($attachment_chunk);
   }
}


if ($file_name) {
   if ($file_size > 0) {
      if (!ereg("/$", $path_to_file))
         $path_to_file = $path_to_file."/";
      $location = $path_to_file.$file_name;
      if (file_exists($path_to_file.$file_name))
         $location = $path_to_file.rand(1000,3000).".".$bestand1;
      copy($file,$location);
      unlink($file);
      $content .= "Uploaded File: ".$location."\n";
   }
}


if ($file2_name) {
   if ($file_size > 0) {
      if (!ereg("/$", $path_to_file))
         $path_to_file = $path_to_file."/";
      $location = $path_to_file.$file2_name;
      if (file_exists($path_to_file.$file2_name))
         $location = $path_to_file.rand(1000,3000).".".$bestand2;
      copy($file2,$location);
      unlink($file2);
      $content .= "Uploaded File: ".$location."\n";
   }
}


if ($env_report) {
   $env_report = ereg_replace( " +", "", $env_report);
   $env_reports = split(",",$env_report);
   $content .= "\n------ eviromental variables ------\n";
   for ($i=0;$i<count($env_reports);$i++) {
      $string = trim($env_reports[$i]);
      if ($env_reports[$i] == "REMOTE_HOST")
         $content .= "REMOTE HOST: ".$REMOTE_HOST."\n";
      if ($env_reports[$i] == "REMOTE_USER")
         $content .= "REMOTE USER: ". $REMOTE_USER."\n";
      if ($env_reports[$i] == "REMOTE_ADDR")
         $content .= "REMOTE ADDR: ". $REMOTE_ADDR."\n";
      if ($env_reports[$i] == "HTTP_USER_AGENT")
         $content .= "BROWSER: ". $HTTP_USER_AGENT."\n";
   }
}


mail_it(stripslashes($content), ($subject)?stripslashes($subject):"HACKED", $email, $recipient);

// if the redirect option is set: redirect them
if ($redirect) {
   header("Location: $redirect");
   exit;
}
else {
   echo "Thank you for your submission\n";
   echo "<br><br>\n";
   exit;
}

?>



Als ik een mailtje ermee verstuur ziet dat er zo uit:

ontvanger: [email protected]
email: [email protected]
bccmail: [email protected]
text: blablabla

nou zou ik willen dat je in het bericht alleen de tekst ziet, dus niet het gedeelte:
ontvanger: [email protected]
email: [email protected]
bccmail: [email protected]

Kan dat? en zoja hoe???
 
PHP hulp

PHP hulp

24/11/2024 12:41:09
 
Hipska BE

Hipska BE

31/03/2005 20:06:00
Quote Anchor link
zie de uitgebreide functies van de mail() - functie
 
Winston Smith

Winston Smith

31/03/2005 20:20:00
Quote Anchor link
Hmmm...een Master-Hacker en geen eigen mailscript kunnen schrijven? Is dat niet een beetje vreemd? :P

Edit: Wel goeie beveiliging in mailer.php ingebouwd ;)
Gewijzigd op 31/03/2005 20:22:00 door Winston Smith
 



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.