0
1
Fork 0
hedera-web-mindshore/rest/misc/mail.php

77 lines
1.8 KiB
PHP
Raw Normal View History

<?php
2018-05-23 10:14:20 +00:00
class Mail extends Vn\Lib\Method {
function run($db) {
$db->query('START TRANSACTION');
2018-05-23 10:14:20 +00:00
$mailer = new Vn\Web\Mailer($db);
$res = $db->query(
2019-09-10 10:00:56 +00:00
'SELECT * FROM vn.mail WHERE `sent` = 0
ORDER BY creationDate
2020-01-23 13:05:58 +00:00
LIMIT 50
FOR UPDATE'
);
2019-09-10 10:00:56 +00:00
$pdfsDir = $db->getValue('SELECT pdfsDir FROM config');
2016-08-31 11:53:46 +00:00
$count = 0;
2018-05-23 10:14:20 +00:00
while ($row = $res->fetch_object()) {
$sent = 1;
$status = 'OK';
try {
2021-10-08 11:18:01 +00:00
$mail = $mailer->createObject($row->receiver, $row->body, $row->subject);
2019-09-13 11:11:15 +00:00
if ($row->replyTo) {
$mail->AddReplyTo($row->replyTo, $row->replyTo);
//$mail->ReturnPath = $row->replyTo;
}
if (!empty($row->attachment)) {
2019-09-10 10:00:56 +00:00
$attachment = "$pdfsDir/{$row->attachment}";
2018-05-23 10:14:20 +00:00
if (file_exists($attachment))
$mail->AddAttachment($attachment, '');
else
2018-05-23 10:14:20 +00:00
throw new Exception("Attachment file could not be found: $attachment");
}
2018-05-23 10:14:20 +00:00
if (!$mail->Send())
throw new Exception($mail->ErrorInfo);
2016-08-31 11:53:46 +00:00
$count++;
2018-05-23 11:09:55 +00:00
} catch (Exception $e) {
$sent = 2;
2018-05-23 10:14:20 +00:00
$status = $e->getMessage();
if ($row->replyTo) {
2019-05-08 10:47:07 +00:00
Vn\Lib\Locale::set('es');
$errorMsg =
2023-01-16 12:59:11 +00:00
'<p>'. s('ITProblemNotification') .'</p>'
.'<p>'. s('ifQuestionsResendEmailToIT') .'</p>'
2019-05-08 10:47:07 +00:00
.'<p style="color: gray">'. $status .'</p>';
$errorMail = $mailer->createObject($row->replyTo,
2019-05-08 10:47:07 +00:00
$errorMsg,
2023-01-16 12:59:11 +00:00
s('automatedMessageNotDelivered')
);
$errorMail->AddStringAttachment(
$mail->getSentMIMEMessage(),
'Undelivered Message',
'8bit',
'message/rfc822'
);
$errorMail->Send();
}
}
2019-09-10 10:00:56 +00:00
$db->query('UPDATE vn.mail SET `sent` = #, status = # WHERE id = #',
2017-11-29 12:55:51 +00:00
[$sent, $status, $row->id]);
}
2018-05-23 10:14:20 +00:00
$db->query('COMMIT');
2016-08-31 11:53:46 +00:00
echo "Total $count mails sent\n";
}
}