01.
<?Php
02.
03.
$name
=
"Name goes here"
;
04.
$email
=
"admin@ggmath.com"
;
05.
$to
=
"$email"
;
06.
$from
=
"admin@ggmath.com"
;
07.
$subject
=
"=?UTF-8?B?"
.
base64_encode
(
"รายงานเครื่อง สถานะต่างๆ"
).
"?="
;
08.
$mainMessage
=
"Hi, here's the file."
;
09.
$fileatt
=
"pdf/MyPDF/MyPDFA3.pdf"
;
10.
$fileatttype
=
"application/pdf"
;
11.
$fileattname
=
"RYG_Item.pdf"
;
12.
$headers
=
"From: $from"
;
13.
14.
$file
=
fopen
(
$fileatt
,
'rb'
);
15.
$data
=
fread
(
$file
,
filesize
(
$fileatt
));
16.
fclose(
$file
);
17.
18.
$semi_rand
= md5(time());
19.
$mime_boundary
=
"==Multipart_Boundary_x{$semi_rand}x"
;
20.
$headers
.=
"\nMIME-Version: 1.0\n"
.
21.
"Content-Type: multipart/mixed;\n"
.
22.
" boundary=\"{$mime_boundary}\""
;
23.
$message
=
"This is a multi-part message in MIME format.\n\n"
.
24.
"-{$mime_boundary}\n"
.
25.
"Content-Type: text/plain; charset=\"iso-8859-1\n"
.
26.
"Content-Transfer-Encoding: 7bit\n\n"
.
27.
$mainMessage
.
"\n\n"
;
28.
$data
=
chunk_split
(
base64_encode
(
$data
));
29.
$message
.=
"--{$mime_boundary}\n"
.
30.
"Content-Type: {$fileatttype};\n"
.
31.
" name=\"{$fileattname}\"\n"
.
32.
"Content-Disposition: attachment;\n"
.
33.
" filename=\"{$fileattname}\"\n"
.
34.
"Content-Transfer-Encoding: base64\n\n"
.
35.
$data
.
"\n\n"
.
36.
"-{$mime_boundary}-\n"
;
37.
38.
if
(mail(
$to
,
$subject
,
$message
,
$headers
)) {
39.
echo
"The email was sent."
;
40.
}
41.
else
{
42.
echo
"There was an error sending the mail."
;
43.
}
44.
?>