prepare($query); $sth->execute($fields); if ( $row = $sth->fetch() ) { $kindlemail = $row['email']; } else { $data["success"] = false; $data["message"] = "No kindle address set"; sendResponse($data); } $data["tomail"] = $kindlemail; $goodtodown = false; if ( isset($_REQUEST['fileid']) ) { $query = "SELECT path, filename FROM books WHERE id=:id"; $sth = $globaldbh->prepare($query); $sth->bindValue(":id", (int) $_REQUEST['fileid'], PDO::PARAM_INT); $sth->execute(); if ( $row = $sth->fetch(PDO::FETCH_ASSOC) ) { $path = $row['path']; $filename = $row['filename']; $curfile = BOOKDIR . "/" . $row['path'] . "/" . $row['filename']; } if ( is_file($curfile) ) { $goodtodown = true; $filesize = filesize($curfile); } } if ( !$goodtodown ) { $data["success"] = false; $data["message"] = "Book not found on disk"; sendResponse($data); } $mail = new PHPMailer(); $mail->isSMTP(); $mail->Host = EMAIL_HOST; $mail->SMTPAuth = true; $mail->Username = EMAIL_USER; $mail->Password = EMAIL_PASS; $mail->SMTPSecure = EMAIL_SECURE; $mail->Port = EMAIL_PORT; $mail->setFrom(EMAIL_FROM, "JAJ Books"); $mail->addAddress($kindlemail, $kindlemail); $mail->isHTML(true); $body = "This is a book sent from JAJ to your Kindle."; $mail->Subject = "Book Delivery"; $mail->Body = $body; $mail->AltBody = $body; $mail->addAttachment($curfile, basename($curfile)); $sent = $mail->send(); //$sent = true; $query = "INSERT INTO log (username, book, sentdate) VALUES(:username, :book, NOW())"; $sth = $globaldbh->prepare($query); $sth->bindValue(":username", $_SESSION['username'], PDO::PARAM_STR); $sth->bindValue(":book", $path . "/" . $filename, PDO::PARAM_STR); $sth->execute(); $data = array(); $data['filename'] = $filename; $data['tomail'] = $kindlemail; $data['success'] = $sent; sendResponse($data); // vim: ts=3 sw=3 et: