Sends email with attached PDF now

This commit is contained in:
7u83 2020-03-09 15:18:28 +00:00
parent 24aefba7e3
commit 90e8ff8580
3 changed files with 54 additions and 7 deletions

7
ka.php
View File

@ -221,7 +221,7 @@ Grund für abweichende Kontoinhabende Person"></textarea>
<input id="a_amount" type="text" name="amount" placeholder="Betrag*"/> <input id="a_amount" type="text" name="amount" placeholder="Betrag*"/>
</div> </div>
<div class="is-col"> <div class="is-col">
<select id="a_currency" name="currency" > <select disabled id="a_currency" name="currency" >
<option value="EUR">EUR</option> <option value="EUR">EUR</option>
<option value="USD">USD</option> <option value="USD">USD</option>
<option value="CHF">CHF</option> <option value="CHF">CHF</option>
@ -291,15 +291,16 @@ Grund für abweichende Kontoinhabende Person"></textarea>
</div> </div>
</div> </div>
<button onclick="addTableRow();" <button onclick="downloadDocument(true);"
class="button is-green">Antrag elektronisch versenden</button> class="button is-green">Antrag elektronisch versenden</button>
<button type="button" onclick="downloadDocument();" <button type="button" onclick="downloadDocument(false);"
class="button is-orange">Herunterladen</button> class="button is-orange">Herunterladen</button>
</div> </div>
</div> </div>
<input type="hidden" id="banktype" name="banktype"/> <input type="hidden" id="banktype" name="banktype"/>
<input type="hidden" id="sendmail" name="sendmail"/>
<!-- <input type="submit" style="display:none" name="submitButton" /> --> <!-- <input type="submit" style="display:none" name="submitButton" /> -->
</form> </form>

View File

@ -30,7 +30,7 @@ function disableCurrency()
document.getElementById("a_currency").disabled=true; document.getElementById("a_currency").disabled=true;
} }
else { else {
document.getElementById("a_currency").disabled=false; document.getElementById("a_currency").disabled=true;
} }
} }
@ -301,7 +301,17 @@ function check_field(fieldid,message){
// //
// //
// //
function downloadDocument() //
function downloadDocument2(){
downloadDocument(true);
}
function downloadDocument1(){
downloadDocument(false);
}
function downloadDocument(mail)
{ {
/* if (!check_field("nickname", "Bitte gib deinen Nicknamen an!")) /* if (!check_field("nickname", "Bitte gib deinen Nicknamen an!"))
return; return;
@ -351,6 +361,14 @@ function downloadDocument()
return; return;
}; };
if (mail){
document.getElementById('sendmail').value="yes";
}
else{
document.getElementById('sendmail').value="no";
}
document.getElementById('banktype').value=banktype; document.getElementById('banktype').value=banktype;

View File

@ -2,6 +2,9 @@
session_start(); session_start();
require "config.php"; require "config.php";
require "PHPMailer/PHPMailer.php";
require "PHPMailer/SMTP.php";
require "PHPMailer/Exception.php";
#$CONVERT_CMD = "/usr/bin/pdftk"; #$CONVERT_CMD = "/usr/bin/pdftk";
@ -405,8 +408,33 @@ $cmd .= " cat output $resultnam.pdf";
exec ($cmd); exec ($cmd);
#var_dump($_POST); #var_dump($_POST);
#echo "CMD: $cmd<br>"; $file = "$resultnam.pdf";
#die;
if ($_POST['sendmail']=='yes'){
$subj = "Kostenerstattungsantrag ueber".calcSum()." EUR";
$mail = new PHPMailer\PHPMailer\PHPMailer();
$mail->IsSMTP();
$mail->setFrom("noc@wikimedia.de");
$mail->Subject = $subj;
$mail->Body = "Kostenerstattungsantragi ...";
$mail->AddAddress("tube@surfpoeten.de");
$mail->AddAttachment( $file , 'antrag.pdf' );
$mail->Host = $mailHost; // Specify main and backup server
$mail->Port = $mailPort; // Set the SMTP port
$mail->SMTPAuth = $mailSMTPAuth;
$mail->Username = $mailUsername;
$mail->Password = $mailPassword;
$mail->SMTPSecure = $mailSMTPSecure; // Enable encryption, 'ssl' also accepted
$rc = $mail->send();
if (!$rc) {
echo 'Mailer Error: ' . $mail->ErrorInfo;
}
echo "Dein Antrag wurde versendet";
die;
}
$file = "$resultnam.pdf"; $file = "$resultnam.pdf";
header('Content-Disposition: attachment; filename="'. basename($file) . '"'); header('Content-Disposition: attachment; filename="'. basename($file) . '"');
header('Content-Length: ' . filesize($file)); header('Content-Length: ' . filesize($file));