Envía un correo con un archivo adjunto de 0kb
Publicado por juan jose (1 intervención) el 04/07/2016 01:02:23
hola tengo un problema y espero que alguien pueda ayudarme.
tengo este código php que envía un email con un archivo png.
el email lo envía y adjunta el archivo pero llega vació (con un peso de 0,0kb).
si alguien pudiera ayudarme lo agradecería mucho
tengo este código php que envía un email con un archivo png.
el email lo envía y adjunta el archivo pero llega vació (con un peso de 0,0kb).
si alguien pudiera ayudarme lo agradecería mucho
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
<?php
$fileatt = "imagen.png"; // Path to the file
$fileatt_type = "image/png"; // File Type
$fileatt_name = "imagen.png"; // Filename that will be used for the file as the attachment
$email_from = "mi_mundo1905@hotmail.com"; // Who the email is from
$email_subject = "Your attached file"; // The Subject of the email
$email_message = "Thanks for visiting mysite.com! Here is your free file.
";
$email_message .= "Thanks for visiting.<br>"; // Message that the email has in it
$email_to = "mi_mundo1905@hotmail.com"; // Who the email is to
$headers = "From: ".$email_from;
$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
$email_message .= "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$email_message .= "\n\n";
$data = chunk_split(base64_encode($data));
$email_message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data .= "\n\n" .
"--{$mime_boundary}--\n";
$ok = @mail($email_to, $email_subject, $email_message, $headers);
if($ok) {
echo "<font face=verdana size=2><center>You file has been sent<br> to the email address you specified.<br>
Make sure to check your junk mail!<br></font>
Click <a href=\"#\" onclick=\"history.back();\">here</a> to return to mysite.com.</center>";
} else {
die("Sorry but the email could not be sent. Please go back and try again!");
}
?>
Valora esta pregunta


0