PHP - Problema con formulario de dattatec

 
Vista:
sin imagen de perfil

Problema con formulario de dattatec

Publicado por juan (1 intervención) el 01/10/2013 23:31:31
Gente buenas tardes, recurro a uds. porque se me ha roto la cabeza.
Tengo una pagina en la cual necesito un formulario para cargar y enviar al mail archivos adjuntos, el tema es que mi proveedor de hosting (DATTATEC) no me soluciona nada.
Les dejo el codigo del PHP que levanta mi formulario a ver si alguien me da una mano, seguramente ya hay algún tema parecido, pero esperan sepan entender que una cabeza bloqueada no da para mucho.
Cambie mi sitio y mail para que no crean que hago publicidad.
Muchas Gracias

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
<?php
# FerozoSite.com Form Email
# CopyRights reserved
 
# Validacion de Datos
function ValidarDatos($campo){
//Array con las posibles cabeceras a utilizar por un spammer
$badHeads = array("Content-Type:",
"MIME-Version:",
"Content-Transfer-Encoding:",
"Return-path:",
"Subject:",
"From:",
"Envelope-to:",
"To:",
"bcc:",
"cc:";);
 
//Comprobamos que entre los datos no se encuentre alguna de
//las cadenas del array. Si se encuentra alguna cadena se
//dirige a una p�ina de Forbidden
foreach($badHeads as $valor){
if(strpos(strtolower($campo), strtolower($valor)) !== false){
return false;
}
}
 
return true;
}
 
function ReemplazarHeader($campo){
//Array con las posibles cabeceras a utilizar por un spammer
$badHeads = array(
array(0=>"[ t]{0,3}Content-Type:[ t]{1}",1=>" '*Content-Type:*' ";),
array(0=>"[ t]{0,3}MIME-Version:[ t]{1}",1=>" '*MIME-Version:*' ";),
array(0=>"[ t]{0,3}Content-Transfer-Encoding:[ t]{1}",1=>" '*Content-Transfer-Encoding:*' ";),
array(0=>"[ t]{0,3}Return-path:[ t]{1}",1=>" '*Return-path:*' ";),
array(0=>"[ t]{0,3}Subject:[ t]{1}",1=>" '*Subject:*' ";),
array(0=>"[ t]{0,3}From:[ t]{1}",1=>" '*From:*' ";),
array(0=>"[ t]{0,3}Envelope-to:[ t]{1}",1=>" '*Envelope-to:*' ";),
array(0=>"[ t]{0,3}(T|t)o:[ t]{1}",1=>" '*To:*' ";),
array(0=>"[ t]{0,3}bcc:[ t]{1}",1=>" '*bcc:*' ";),
array(0=>"[ t]{0,3}cc:[ t]{1}",1=>" '*cc:*' ";)
);
 
//Comprobamos que entre los datos no se encuentre alguna de
//las cadenas del array. Si se encuentra alguna cadena se
//dirige a una p�ina de Forbidden
foreach($badHeads as $a_badheader){
$campo = eregi_replace($a_badheader[0], $a_badheader[1], $campo);
}
 
return $campo;
}
 
 
function CodificarQP ($str) {
global $eol;
 
$encoded = ArreglarEOL($str);
if (substr($encoded, -(strlen($eol))) != $eol)
$encoded .= $eol;
 
// Reemplazar cada caracter ascii alto, control e =
$encoded = preg_replace('/([00-10131416-3775177-377])/e',
"'='.sprintf('%02X', ord('1'))", $encoded);
// Reemplazar cada espacio y tabulador cuando es el último caracter en una línea
$encoded = preg_replace("/([1140])".$eol."/e",
"'='.sprintf('%02X', ord('1')).'".$eol."'", $encoded);
 
// Máximo largo de línea de 76 caracteres antes de retorno de carro y nueva línea (74 + space + '=')
$encoded = AdaptarTexto($encoded, 74, true);
 
return $encoded;
}
 
 
function ArreglarEOL($str) {
global $eol;
 
$str = str_replace("rn", "n", $str);
$str = str_replace("r", "n", $str);
$str = str_replace("n", $eol, $str);
return $str;
}
 
 
function AdaptarTexto($message, $length, $qp_mode = false) {
global $eol;
 
        $soft_break = ($qp_mode) ? sprintf(" =%s", $eol) : $eol;
 
        $message = ArreglarEOL($message);
        if (substr($message, -1) == $eol)
            $message = substr($message, 0, -1);
 
        $line = explode($eol, $message);
        $message = "";
        for ($i=0 ;$i < count($line); $i++)
        {
          $line_part = explode(" ", $line[$i]);
          $buf = "";
          for ($e = 0; $e<count($line_part); $e++)
          {
              $word = $line_part[$e];
              if ($qp_mode and (strlen($word) > $length))
              {
                $space_left = $length - strlen($buf) - 1;
                if ($e != 0)
                {
                    if ($space_left > 20)
                    {
                        $len = $space_left;
                        if (substr($word, $len - 1, 1) == "=";)
                          $len--;
                        elseif (substr($word, $len - 2, 1) == "=";)
                          $len -= 2;
                        $part = substr($word, 0, $len);
                        $word = substr($word, $len);
                        $buf .= " " . $part;
                        $message .= $buf . sprintf("=%s", $eol);
                    }
                    else
                    {
                        $message .= $buf . $soft_break;
                    }
                    $buf = "";
                }
                while (strlen($word) > 0)
                {
                    $len = $length;
                    if (substr($word, $len - 1, 1) == "=";)
                        $len--;
                    elseif (substr($word, $len - 2, 1) == "=";)
                        $len -= 2;
                    $part = substr($word, 0, $len);
                    $word = substr($word, $len);
 
                    if (strlen($word) > 0)
                        $message .= $part . sprintf("=%s", $eol);
                    else
                        $buf = $part;
                }
              }
              else
              {
                $buf_o = $buf;
                $buf .= ($e == 0) ? $word : (" " . $word);
 
                if (strlen($buf) > $length and $buf_o != "";)
                {
                    $message .= $buf_o . $soft_break;
                    $buf = $word;
                }
              }
          }
          $message .= $buf . $eol;
        }
 
        return $message;
}
 
 
$s_mailer_type = 'mail';
 
if (!file_exists('E:/php5/PhpCommon/fzo.mail.php') && $s_mailer_type == 'smtp') {
$s_mailer_type = 'mail';
}
 
if ($s_mailer_type == 'smtp') {
function _fzo_mail( $s_to, $s_subject, $s_message, $s_additional_headers='') {
 
require_once("fzo.mail.php";);
 
global $eol;
 
if (empty($eol)) {
$eol = "n";
}
 
$mail = new SMTP("localhost",'','');
 
$s_from = 'no-reply@misitio.com';
 
if (empty($s_from) || $s_from == ('<!--%' . 'email_from_address' . '%-->')) {
$s_host = $_SERVER["HTTP_HOST"];
$s_host = ereg_replace("www.", "", $s_host);
$s_from = "no-reply@" . $s_host;
}
 
$s_header = $mail->make_header(
$s_from,
$s_to,
$s_subject,
'3',
'',
''
);
 
$s_additional_headers = trim($s_header) . $eol . $s_additional_headers;
 
// Se envia el correo y se verifica el error
$error = $mail->smtp_send($s_from, $s_to, $s_additional_headers, $s_message, '', '');
 
if ($error == "0";) {
//echo "E-mail enviado correctamente";
return true;
}
else {
//echo "Error al enviar email: " . $error . "n";
return false;
}
 
}
}
 
 
# Is the OS Windows or Mac or Linux
if (strtoupper(substr(PHP_OS,0,3)=='WIN')) {
  $eol="rn";
} elseif (strtoupper(substr(PHP_OS,0,3)=='MAC')) {
  $eol="r";
} else {
  $eol="n";
}
 
$now = date("YmdHis";);
 
$s_mailer_enabled = 'TRUE';
 
# To Email Address
$emailaddress="mail@misitio.com";
$emailaddressfrom="no-reply@misitio.com";
# Message Subject
$emailsubject="email de contacto desde ".$_SERVER['HTTP_HOST'];
# Message Body
$body_txt_prefix_data="";
$body_txt_separator_data=": ";
$body_txt_sufix_data=$eol;
 
$body_txt_prefix="Datos del Formulario:".$eol;
$body_txt_data="";
$body_txt_sufix=$eol."FerozoSite.com!";
 
 
$body_html_prefix_data =
"<tr>
<td>";
$body_html_separator_data=": </td><td>";
$body_html_sufix_data="</td>
</tr>
";
 
$body_html_prefix="<html>
<body>
<table>
<tr>
<td colspan="2">Datos del Formulario:</td>
</tr>";
$body_html_data="";
$body_html_sufix="<tr>
<td colspan="2"><br/>FerozoSite.com!</td>
</tr>
</table>
</body>
</html>";
 
# Get Data
foreach($_POST as $s_name => $s_value) {
if (strtolower($s_name) != 'submit') {
$s_name = ucwords(str_replace("_"," ",$s_name));
$s_value = stripslashes ($s_value);
$body_txt_data.=$body_txt_prefix_data.$s_name.$body_txt_separator_data.$s_value.$body_txt_sufix_data;
$body_html_data.=$body_html_prefix_data.$s_name.$body_html_separator_data.$s_value.$body_html_sufix_data;
}
}
 
# Merge Data
$body_txt=$body_txt_prefix.$body_txt_data.$body_txt_sufix;
$body_html=$body_html_prefix.$body_html_data.$body_html_sufix;
 
$body_txt = ReemplazarHeader($body_txt);
$body_html = ReemplazarHeader($body_html);
 
# Common Headers
$headers .= 'From: '.$emailaddressfrom.$eol;
$headers .= 'Reply-To: '.$emailaddressfrom.$eol;
$headers .= 'Return-Path: '.$emailaddressfrom.$eol;    // these two to set reply address
$headers .= "X-Mailer: PHP v".phpversion().$eol;   // These two to help avoid spam-filters
# Boundry for marking the split & Multitype Headers
$mime_boundary=md5(time());
$headers .= 'MIME-Version: 1.0'.$eol;
# Setup for text OR html
$headers .= "Content-Type: multipart/alternative; boundary="".$mime_boundary.""".$eol;
$headers .= "Message-ID: <".$now.".TheSystem@".$_SERVER['SERVER_NAME'].">".$eol;
$msg = "";
# Text Version
$msg .= "--".$mime_boundary.$eol;
$msg .= "Content-Type: text/plain; charset=iso-8859-1".$eol;
$msg .= "Content-Transfer-Encoding: quoted-printable".$eol.$eol;
$msg .= CodificarQP($body_txt).$eol;
# HTML Version
$msg .= "--".$mime_boundary.$eol;
$msg .= "Content-Type: text/html; charset=iso-8859-1".$eol;
$msg .= "Content-Transfer-Encoding: quoted-printable".$eol.$eol;
$msg .= CodificarQP("<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">";).$eol;
$msg .= CodificarQP($body_html).$eol.$eol;
 
/*
# Setup for attachment
$msg .= "Content-Type: multipart/related".$eol;

# Attachment
$msg .= "--".$mime_boundary.$eol;
$msg .= "Content-Type: application/pdf; name="".$letter.""".$eol;  // sometimes i have to send MS Word, use 'msword' instead of 'pdf'
$msg .= "Content-Transfer-Encoding: base64".$eol;
$msg .= "Content-Disposition: attachment; filename="".$letter.""".$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.
 
//Ejemplo de llamadas a la funcion
if(ValidarDatos($emailaddress) && ValidarDatos($emailsubject) /*&& ValidarDatos($body_txt) && ValidarDatos($body_html)*/){
# SEND THE EMAIL
if ($s_mailer_enabled == 'TRUE') {
if ($s_mailer_type=='smtp') {
$resp = _fzo_mail($emailaddress, $emailsubject, $msg, $headers);
}
else {
$resp = mail($emailaddress, $emailsubject, $msg, $headers);
}
}
else {
$resp = false;
}
}
else {
$resp = false;
}
 
 
if($resp) {
$s_location = "formok.php";
}
else {
$s_location = "formerror.php";
}
 
header("Location: ./$s_location";);
 
?>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder