Mailversand bei Finanzerfassung
This commit is contained in:
parent
d644adee31
commit
082047700f
@ -67,7 +67,8 @@ if ($function == 'save_with_files')
|
|||||||
$row = $result->fetch_array();
|
$row = $result->fetch_array();
|
||||||
if ($row['fid'] == '' AND $fid_edit == '-1')
|
if ($row['fid'] == '' AND $fid_edit == '-1')
|
||||||
{
|
{
|
||||||
$sql1 = $db->query("INSERT INTO jumi_finanzen ( datum
|
$sql1 = $db->query("INSERT INTO jumi_finanzen ( uid
|
||||||
|
, datum
|
||||||
, beschreibung
|
, beschreibung
|
||||||
, firma
|
, firma
|
||||||
, art
|
, art
|
||||||
@ -75,7 +76,8 @@ if ($function == 'save_with_files')
|
|||||||
, bemerkung
|
, bemerkung
|
||||||
)
|
)
|
||||||
VALUES
|
VALUES
|
||||||
( '$datum_form'
|
( '$uid'
|
||||||
|
, '$datum_form'
|
||||||
, '$beschreibung'
|
, '$beschreibung'
|
||||||
, '$firma'
|
, '$firma'
|
||||||
, '$art'
|
, '$art'
|
||||||
@ -160,7 +162,8 @@ if ($function == 'save_without_files')
|
|||||||
|
|
||||||
$datum = date("Y-m-d H:i:s");
|
$datum = date("Y-m-d H:i:s");
|
||||||
if($fid_edit == '-1'){
|
if($fid_edit == '-1'){
|
||||||
$sql1 = $db->query("INSERT INTO jumi_finanzen ( datum
|
$sql1 = $db->query("INSERT INTO jumi_finanzen ( uid
|
||||||
|
, datum
|
||||||
, beschreibung
|
, beschreibung
|
||||||
, firma
|
, firma
|
||||||
, art
|
, art
|
||||||
@ -168,7 +171,8 @@ if ($function == 'save_without_files')
|
|||||||
, bemerkung
|
, bemerkung
|
||||||
)
|
)
|
||||||
VALUES
|
VALUES
|
||||||
( '$datum_form'
|
( '$uid'
|
||||||
|
, '$datum_form'
|
||||||
, '$beschreibung'
|
, '$beschreibung'
|
||||||
, '$firma'
|
, '$firma'
|
||||||
, '$art'
|
, '$art'
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
<?php
|
<?php
|
||||||
error_reporting(E_ALL);
|
|
||||||
require_once("../config.inc.php");
|
require_once("../config.inc.php");
|
||||||
#require('../phpmailer/class.phpmailer.php');
|
#require('../phpmailer/class.phpmailer.php');
|
||||||
|
|
||||||
@ -66,44 +65,6 @@ for ($i = 0; $i < sizeof($empfaenger); $i++) {
|
|||||||
$mail_bcc = array_unique($mail_bcc);
|
$mail_bcc = array_unique($mail_bcc);
|
||||||
|
|
||||||
|
|
||||||
function save_mail($mail)
|
|
||||||
{
|
|
||||||
// Mails in IMAP Gesendete schieben
|
|
||||||
#####################################################
|
|
||||||
## Wegen dieser Funktion, wurde PHP Version aktiviert. Siehe ../Hinweise_zu_php8.txt
|
|
||||||
#####################################################
|
|
||||||
|
|
||||||
|
|
||||||
// # Script um sich $path anzeigen zu lassen:
|
|
||||||
// $mbox = imap_open("{imap.ionos.de:993/imap/ssl}", "$mailjumi", "$mailpwd", OP_HALFOPEN)
|
|
||||||
// or die("can't connect: " . imap_last_error());
|
|
||||||
// if($mbox){
|
|
||||||
// echo "connect";
|
|
||||||
// }else{
|
|
||||||
// echo "fail";
|
|
||||||
// }
|
|
||||||
// $list = imap_getmailboxes($mbox, "{imap.ionos.de:993/imap/ssl}", "*");
|
|
||||||
// if (is_array($list)) {
|
|
||||||
// foreach ($list as $key => $val) {
|
|
||||||
// echo "($key) ";
|
|
||||||
// echo imap_utf7_decode($val->name) . ",";
|
|
||||||
// echo "'" . $val->delimiter . "',";
|
|
||||||
// echo $val->attributes . "<br />\n";
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// echo "imap_getmailboxes failed: " . imap_last_error() . "\n";
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// imap_close($mbox);
|
|
||||||
|
|
||||||
$path = "{imap.ionos.de:993/imap/ssl}Gesendete Objekte";
|
|
||||||
$imapStream = imap_open($path, $mail->Username, $mail->Password);
|
|
||||||
# Letzter Flag Seen, damit die Mail bereits als gelesen in gesendete Objekte eingestellt wird
|
|
||||||
$result = imap_append($imapStream, $path, $mail->getSentMIMEMessage(),"\Seen");
|
|
||||||
imap_close($imapStream);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
$mail = new PHPMailer();
|
$mail = new PHPMailer();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -148,9 +109,9 @@ try {
|
|||||||
//$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
|
//$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
|
||||||
|
|
||||||
$mail->send();
|
$mail->send();
|
||||||
if (save_mail($mail)) {
|
require_once("../controller/func_save_mail.php");
|
||||||
#echo "Message saved!";
|
save_mail($mail);
|
||||||
}
|
|
||||||
echo '<div class="alert alert-success"><i class="fa fa-fw fa-thumbs-up"></i> Mail wurde versendet!</div>|***|success';
|
echo '<div class="alert alert-success"><i class="fa fa-fw fa-thumbs-up"></i> Mail wurde versendet!</div>|***|success';
|
||||||
}
|
}
|
||||||
catch (Exception $e) {
|
catch (Exception $e) {
|
||||||
|
206
controller/cronjob_finanzen.php
Normal file
206
controller/cronjob_finanzen.php
Normal file
@ -0,0 +1,206 @@
|
|||||||
|
<?php
|
||||||
|
error_reporting(E_ALL);
|
||||||
|
# https://console.cron-job.org/jobs
|
||||||
|
|
||||||
|
require_once("../config/datenbankanbindung.php");
|
||||||
|
require_once("../controller/func_get_parameter.php");
|
||||||
|
require_once("../controller/func_save_mail.php");
|
||||||
|
header('Content-Type: text/html; charset=utf-8');
|
||||||
|
$db = dbconnect();
|
||||||
|
use PHPMailer\PHPMailer\PHPMailer;
|
||||||
|
use PHPMailer\PHPMailer\Exception;
|
||||||
|
|
||||||
|
require '../PHPMailer6/src/Exception.php';
|
||||||
|
require '../PHPMailer6/src/PHPMailer.php';
|
||||||
|
require '../PHPMailer6/src/SMTP.php';
|
||||||
|
|
||||||
|
$mailjumi = get_parameter(1);
|
||||||
|
$absender = get_parameter(2);
|
||||||
|
$mailpwd = get_parameter(3);
|
||||||
|
$fmt = new NumberFormatter( 'de_DE', NumberFormatter::CURRENCY );
|
||||||
|
|
||||||
|
|
||||||
|
$query = "SELECT fid, uid, beschreibung, firma, art, betrag, bemerkung FROM jumi_finanzen where mailversand is NULL ORDER BY datum ASC";
|
||||||
|
$result = $db->query( $query)
|
||||||
|
or die ("Cannot execute query");
|
||||||
|
|
||||||
|
while ($row = $result->fetch_array()){
|
||||||
|
|
||||||
|
$result_user = $db->query("SELECT vorname, nachname
|
||||||
|
FROM jumi_admin
|
||||||
|
WHERE uid = $row[uid]");
|
||||||
|
$row_user = $result_user->fetch_array();
|
||||||
|
if($row['art'] == 'A'){
|
||||||
|
$art = 'Ausgabe';
|
||||||
|
$betrag = $row['betrag']*(-1);
|
||||||
|
}
|
||||||
|
if($row['art'] == 'E'){
|
||||||
|
$art = 'Einnahme';
|
||||||
|
$betrag = $betrag;
|
||||||
|
}
|
||||||
|
|
||||||
|
$betrag = $fmt->formatCurrency($betrag, "EUR");
|
||||||
|
|
||||||
|
$mail = new PHPMailer();
|
||||||
|
$attachment = array();
|
||||||
|
|
||||||
|
try {
|
||||||
|
//Server settings
|
||||||
|
$mail->isSMTP(); //Send using SMTP
|
||||||
|
$mail->CharSet = 'UTF-8';
|
||||||
|
$mail->Encoding = 'base64';
|
||||||
|
$mail->SMTPDebug = 0;
|
||||||
|
$mail->Host = 'smtp.ionos.de'; //Set the SMTP server to send through
|
||||||
|
$mail->SMTPAuth = true; //Enable SMTP authentication
|
||||||
|
$mail->Username = "$mailjumi"; //SMTP username
|
||||||
|
$mail->Password = "$mailpwd"; //SMTP password
|
||||||
|
$mail->Port = 465; //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
|
||||||
|
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
|
||||||
|
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
|
||||||
|
# Priority: Options: null (default), 1 = High, 3 = Normal, 5 = low
|
||||||
|
# $mail->Priority = 1;
|
||||||
|
|
||||||
|
//Recipients
|
||||||
|
//$mail->SetFrom($_POST["userEmail"], $_POST["userName"]);
|
||||||
|
//$mail->AddReplyTo($_POST["userEmail"], $_POST["userName"]);
|
||||||
|
$mail->SetFrom("$mailjumi", "$absender");
|
||||||
|
$mail->AddAddress("$mailjumi", "$absender");
|
||||||
|
$mail->AddReplyTo("$mailjumi", "$absender");
|
||||||
|
//$mail->addCC('cc@example.com');
|
||||||
|
|
||||||
|
$query1 = "SELECT filename, originalname FROM jumi_finanzen_uploads WHERE fid=$row[fid]";
|
||||||
|
$result1 = $db->query($query1)
|
||||||
|
or die ("Cannot execute query1");
|
||||||
|
|
||||||
|
while ($row1 = $result1->fetch_array()){
|
||||||
|
$a = ['filename'=>"$row1[filename]"];
|
||||||
|
$b = ['name'=>"$row1[originalname]"];
|
||||||
|
$attachment[] = array_merge($a, $b);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//Attachments
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if (sizeof($attachment) > 0) {
|
||||||
|
foreach($attachment as $files) {
|
||||||
|
$mail->AddAttachment($files['filename'], $files['name']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Content
|
||||||
|
$mail->isHTML(true); //Set email format to HTML
|
||||||
|
$mail->Subject = "Neue $art erfasst";
|
||||||
|
$text = "
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Neue $art erfasst</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<font face='Arial' size='2'>
|
||||||
|
Hallo,<br><br>
|
||||||
|
im Admintool wurde eine $art erfasst:
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td valign='top'>
|
||||||
|
<font face='Arial' size='2'>
|
||||||
|
<b>Benutzer:</b>
|
||||||
|
</font>
|
||||||
|
</td>
|
||||||
|
<td valign='top'>
|
||||||
|
<font face='Arial' size='2'>
|
||||||
|
$row_user[vorname] $row_user[nachname]
|
||||||
|
</font>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td valign='top'>
|
||||||
|
<font face='Arial' size='2'>
|
||||||
|
<b>Art:</b>
|
||||||
|
</font>
|
||||||
|
</td>
|
||||||
|
<td valign='top'>
|
||||||
|
<font face='Arial' size='2'>
|
||||||
|
$art
|
||||||
|
</font>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td valign='top'>
|
||||||
|
<font face='Arial' size='2'>
|
||||||
|
<b>Beschreibung/Firma:</b>
|
||||||
|
</font>
|
||||||
|
</td>
|
||||||
|
<td valign='top'>
|
||||||
|
<font face='Arial' size='2'>
|
||||||
|
$row[beschreibung] / $row[firma]
|
||||||
|
</font>
|
||||||
|
</td>
|
||||||
|
</tr>";
|
||||||
|
if($row['bemerkung'] != ''){
|
||||||
|
$text .= "
|
||||||
|
<tr>
|
||||||
|
<td valign='top'>
|
||||||
|
<font face='Arial' size='2'>
|
||||||
|
<b>Bemerkung:</b>
|
||||||
|
</font>
|
||||||
|
</td>
|
||||||
|
<td valign='top'>
|
||||||
|
<font face='Arial' size='2'>
|
||||||
|
$row[bemerkung]
|
||||||
|
</font>
|
||||||
|
</td>
|
||||||
|
</tr>";
|
||||||
|
}
|
||||||
|
$text .= "
|
||||||
|
<tr>
|
||||||
|
<td valign='top'>
|
||||||
|
<font face='Arial' size='2'>
|
||||||
|
<b>Betrag:</b>
|
||||||
|
</font>
|
||||||
|
</td>
|
||||||
|
<td valign='top'>
|
||||||
|
<font face='Arial' size='2'>
|
||||||
|
$betrag
|
||||||
|
</font>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
<br>
|
||||||
|
Diese Mail wurde automatisch erstellt!
|
||||||
|
<p>
|
||||||
|
Vielen Dank,<br>
|
||||||
|
JU & MI
|
||||||
|
</body>
|
||||||
|
</html>";
|
||||||
|
|
||||||
|
$mail->Body = $text;
|
||||||
|
//$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
|
||||||
|
|
||||||
|
$mail->send();
|
||||||
|
if($mail){
|
||||||
|
|
||||||
|
save_mail($mail);
|
||||||
|
$datum = date("Y-m-d H:i:s");
|
||||||
|
$sql1 = $db->query( "UPDATE jumi_finanzen
|
||||||
|
SET mailversand = '$datum'
|
||||||
|
WHERE fid = $row[fid]
|
||||||
|
" );
|
||||||
|
|
||||||
|
}
|
||||||
|
# echo "<hr><pre>";
|
||||||
|
# print_r($mail);
|
||||||
|
# echo "</pre><hr>";
|
||||||
|
# echo '<div class="alert alert-success"><i class="fa fa-fw fa-thumbs-up"></i> Mail wurde versendet!</div><br>';
|
||||||
|
}
|
||||||
|
catch (Exception $e) {
|
||||||
|
# echo "<div class='alert alert-danger'><i class='fa fa-fw fa-thumbs-down'></i> Es konnte <b>keine Mail</b> verschickt werden! Mailer Error: {$mail->ErrorInfo}</div><br>";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
41
controller/func_save_mail.php
Normal file
41
controller/func_save_mail.php
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
function save_mail($mail)
|
||||||
|
{
|
||||||
|
// Mails in IMAP Gesendete schieben
|
||||||
|
#####################################################
|
||||||
|
## Wegen dieser Funktion, wurde PHP Version aktiviert. Siehe ../Hinweise_zu_php8.txt
|
||||||
|
#####################################################
|
||||||
|
|
||||||
|
|
||||||
|
// # Script um sich $path anzeigen zu lassen:
|
||||||
|
// $mbox = imap_open("{imap.ionos.de:993/imap/ssl}", "$mailjumi", "$mailpwd", OP_HALFOPEN)
|
||||||
|
// or die("can't connect: " . imap_last_error());
|
||||||
|
// if($mbox){
|
||||||
|
// echo "connect";
|
||||||
|
// }else{
|
||||||
|
// echo "fail";
|
||||||
|
// }
|
||||||
|
// $list = imap_getmailboxes($mbox, "{imap.ionos.de:993/imap/ssl}", "*");
|
||||||
|
// if (is_array($list)) {
|
||||||
|
// foreach ($list as $key => $val) {
|
||||||
|
// echo "($key) ";
|
||||||
|
// echo imap_utf7_decode($val->name) . ",";
|
||||||
|
// echo "'" . $val->delimiter . "',";
|
||||||
|
// echo $val->attributes . "<br />\n";
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// echo "imap_getmailboxes failed: " . imap_last_error() . "\n";
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// imap_close($mbox);
|
||||||
|
|
||||||
|
$path = "{imap.ionos.de:993/imap/ssl}Gesendete Objekte";
|
||||||
|
$imapStream = imap_open($path, $mail->Username, $mail->Password);
|
||||||
|
# Letzter Flag Seen, damit die Mail bereits als gelesen in gesendete Objekte eingestellt wird
|
||||||
|
$result = imap_append($imapStream, $path, $mail->getSentMIMEMessage(),"\Seen");
|
||||||
|
imap_close($imapStream);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
26
dashboard/test2.php
Normal file
26
dashboard/test2.php
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
$attachment = array();
|
||||||
|
|
||||||
|
$a = ['filename'=>'../media/file_upload/finanzen/20230420_111236_RG_100121618035.pdf'];
|
||||||
|
$b = ['name'=>'RG_100121618035.pdf'];
|
||||||
|
$attachment[] = array_merge($a, $b);
|
||||||
|
|
||||||
|
$a = ['filename'=>'../media/file_upload/finanzen/20230420_111413_RG_100119951099.pdf'];
|
||||||
|
$b = ['name'=>'RG_100119951099.pdf'];
|
||||||
|
$attachment[] = array_merge($a, $b);
|
||||||
|
|
||||||
|
$a = ['filename'=>'../media/file_upload/finanzen/20230420_111614_RG_100117336090.pdf'];
|
||||||
|
$b = ['name'=>'RG_100117336090.pdf'];
|
||||||
|
$attachment[] = array_merge($a, $b);
|
||||||
|
|
||||||
|
echo"<pre>";
|
||||||
|
print_r($attachment);
|
||||||
|
echo"</pre><hr>";
|
||||||
|
|
||||||
|
foreach($attachment as $files) {
|
||||||
|
echo "$files[filename] --> $files[name] <br>";
|
||||||
|
echo "<br>";
|
||||||
|
}
|
||||||
|
|
||||||
|
echo sizeof($attachment);
|
||||||
|
?>
|
Loading…
x
Reference in New Issue
Block a user