3 require_once ("config.php");
\r
4 require_once "resources/PHPMailer/class.phpmailer.php";
\r
5 require_once "book.php";
\r
7 if (is_null ($config['cops_mail_configuration']) ||
\r
8 !is_array ($config['cops_mail_configuration']) ||
\r
9 empty ($config['cops_mail_configuration']["smtp.host"]) ||
\r
10 empty ($config['cops_mail_configuration']["address.from"])) {
\r
11 echo "NOK. bad configuration of $config ['cops_mail_configuration']";
\r
15 $idData = $_REQUEST["data"];
\r
16 if (empty ($idData)) {
\r
17 echo 'No data sent.';
\r
20 $emailDest = $_REQUEST["email"];
\r
21 if (empty ($emailDest)) {
\r
22 echo 'No email sent.';
\r
26 $book = Book::getBookByDataId($idData);
\r
27 $data = $book->getDataById ($idData);
\r
29 if (filesize ($data->getLocalPath ()) > 10 * 1024 * 1024) {
\r
30 echo 'Attachement too big';
\r
34 $mail = new PHPMailer;
\r
37 $mail->Timeout = 30; // 30 seconds as some files can be big
\r
38 $mail->Host = $config['cops_mail_configuration']["smtp.host"];
\r
39 if (!empty ($config['cops_mail_configuration']["smtp.secure"])) {
\r
40 $mail->SMTPSecure = $config['cops_mail_configuration']["smtp.secure"];
\r
43 $mail->SMTPAuth = !empty ($config['cops_mail_configuration']["smtp.username"]);
\r
44 if (!empty ($config['cops_mail_configuration']["smtp.username"])) $mail->Username = $config['cops_mail_configuration']["smtp.username"];
\r
45 if (!empty ($config['cops_mail_configuration']["smtp.password"])) $mail->Password = $config['cops_mail_configuration']["smtp.password"];
\r
46 if (!empty ($config['cops_mail_configuration']["smtp.secure"])) $mail->SMTPSecure = $config['cops_mail_configuration']["smtp.secure"];
\r
48 $mail->From = $config['cops_mail_configuration']["address.from"];
\r
49 $mail->FromName = $config['cops_title_default'];
\r
51 foreach (explode (";", $emailDest) as $emailAddress) {
\r
52 if (empty ($emailAddress)) { continue; }
\r
53 $mail->AddAddress($emailAddress);
\r
56 $mail->AddAttachment($data->getLocalPath ());
\r
58 $mail->IsHTML(false);
\r
59 $mail->Subject = 'Sent by COPS';
\r
60 $mail->Body = 'Sent by COPS';
\r
62 if(!$mail->Send()) {
\r
63 echo localize ("mail.messagenotsent");
\r
64 echo 'Mailer Error: ' . $mail->ErrorInfo;
\r
68 echo localize ("mail.messagesent");
\r