Add a new file to handle mail sending. re #53
This commit is contained in:
parent
1f4db62fc1
commit
859c7f9bc6
68
sendtomail.php
Normal file
68
sendtomail.php
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
require_once ("config.php");
|
||||||
|
require "resources/PHPMailer/class.phpmailer.php";
|
||||||
|
require "book.php";
|
||||||
|
|
||||||
|
if (is_null ($config['cops_mail_configuration']) ||
|
||||||
|
!is_array ($config['cops_mail_configuration']) ||
|
||||||
|
empty ($config['cops_mail_configuration']["smtp.host"]) ||
|
||||||
|
empty ($config['cops_mail_configuration']["address.from"])) {
|
||||||
|
echo "NOK. bad configuration of $config ['cops_mail_configuration']";
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$idData = $_REQUEST["data"];
|
||||||
|
if (empty ($idData)) {
|
||||||
|
echo 'No data sent.';
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$emailDest = $_REQUEST["email"];
|
||||||
|
if (empty ($emailDest)) {
|
||||||
|
echo 'No email sent.';
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$book = Book::getBookByDataId($idData);
|
||||||
|
$data = $book->getDataById ($idData);
|
||||||
|
|
||||||
|
if (filesize ($data->getLocalPath ()) > 10 * 1024 * 1024) {
|
||||||
|
echo 'Attachement too big';
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
$mail = new PHPMailer;
|
||||||
|
|
||||||
|
$mail->IsSMTP();
|
||||||
|
$mail->Timeout = 30; // 30 seconds as some files can be big
|
||||||
|
$mail->Host = $config['cops_mail_configuration']["smtp.host"];
|
||||||
|
if (!empty ($config['cops_mail_configuration']["smtp.secure"])) {
|
||||||
|
$mail->SMTPSecure = $config['cops_mail_configuration']["smtp.secure"];
|
||||||
|
$mail->Port = 465;
|
||||||
|
}
|
||||||
|
$mail->SMTPAuth = !empty ($config['cops_mail_configuration']["smtp.username"]);
|
||||||
|
if (!empty ($config['cops_mail_configuration']["smtp.username"])) $mail->Username = $config['cops_mail_configuration']["smtp.username"];
|
||||||
|
if (!empty ($config['cops_mail_configuration']["smtp.password"])) $mail->Password = $config['cops_mail_configuration']["smtp.password"];
|
||||||
|
if (!empty ($config['cops_mail_configuration']["smtp.secure"])) $mail->SMTPSecure = $config['cops_mail_configuration']["smtp.secure"];
|
||||||
|
|
||||||
|
$mail->From = $config['cops_mail_configuration']["address.from"];
|
||||||
|
$mail->FromName = $config['cops_title_default'];
|
||||||
|
|
||||||
|
$mail->AddAddress($emailDest);
|
||||||
|
|
||||||
|
$mail->AddAttachment($data->getLocalPath ());
|
||||||
|
|
||||||
|
$mail->IsHTML(false);
|
||||||
|
$mail->Subject = 'Sent by COPS';
|
||||||
|
$mail->Body = 'Sent by COPS';
|
||||||
|
|
||||||
|
if(!$mail->Send()) {
|
||||||
|
echo 'Message could not be sent.';
|
||||||
|
echo 'Mailer Error: ' . $mail->ErrorInfo;
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
echo 'Message has been sent';
|
||||||
|
|
||||||
|
|
||||||
|
?>
|
Loading…
Reference in a new issue