aboutsummaryrefslogtreecommitdiffhomepage
path: root/inc/3rdparty/libraries/send2kindle/send.php
diff options
context:
space:
mode:
Diffstat (limited to 'inc/3rdparty/libraries/send2kindle/send.php')
-rw-r--r--inc/3rdparty/libraries/send2kindle/send.php69
1 files changed, 69 insertions, 0 deletions
diff --git a/inc/3rdparty/libraries/send2kindle/send.php b/inc/3rdparty/libraries/send2kindle/send.php
new file mode 100644
index 00000000..a4861d30
--- /dev/null
+++ b/inc/3rdparty/libraries/send2kindle/send.php
@@ -0,0 +1,69 @@
1<?php
2/**
3 * Send to kindle email
4 * @author jwest <jwest@jwest.pl>
5 */
6class Send {
7
8 /**
9 * Your kindle email
10 * @var string
11 */
12 private $_kindle_email;
13
14 /**
15 * Your email (must be added on amazon)
16 * @var string
17 */
18 private $_email;
19
20 /**
21 * Prepare mail
22 * @param string $kindle_email your kindle email
23 * @param string $email email for send to kindle
24 */
25 public function __construct($kindle_email, $email)
26 {
27 $this->_kindle_email = $kindle_email;
28 $this->_email = $email;
29 }
30
31 /**
32 * Send file
33 * @param string $file path to file
34 * @return bool
35 */
36 public function send($file)
37 {
38 //prepare file
39 $file_size = filesize($file);
40 $filename = basename($file);
41 $handle = fopen($file, "r");
42 $content = fread($handle, $file_size);
43 fclose($handle);
44 $content = chunk_split(base64_encode($content));
45
46 $uid = md5(uniqid(time()));
47
48 //generate header for mail
49 $header = "From: News2Kindle <".$this->_email.">\r\n";
50 $header .= "MIME-Version: 1.0\r\n";
51 $header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
52 $header .= "This is a multi-part message in MIME format.\r\n";
53 $header .= "--".$uid."\r\n";
54 $header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
55 $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
56 $header .= "send via News2Kindle script\r\n\r\n";
57 $header .= "--".$uid."\r\n";
58 $header .= "Content-Type: application/x-mobipocket-ebook; name=\"".$filename."\"\r\n";
59 $header .= "Content-Transfer-Encoding: base64\r\n";
60 $header .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
61 $header .= $content."\r\n\r\n";
62 $header .= "--".$uid."--";
63
64 //send mail
65 return mail( $this->_kindle_email, '[newsToKindle] ' . $filename, "", $header );
66 }
67}
68
69?> \ No newline at end of file