Fix exception reporting.

- Repariert: Fehlerberichte konnten nicht gesendet werden.
This commit is contained in:
2017-09-18 21:19:49 +02:00
parent 08bd137e94
commit 443a6b48e7
10 changed files with 67 additions and 64 deletions

View File

@ -1,53 +1,52 @@
<?php
require(__DIR__ . '/PHPMailer/PHPMailerAutoload.php');
$reportId = $_POST['report_id'];
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->Host = 'nephrowiki.de';
$mail->Username = 'zaareloaded@nephrowiki.de';
$mail->Password = 'ooZ1eiJa';
// $mail->SMTPSecure = 'tls';
$mail->Port = 25;
function sendMail() {
$to = 'dk@doktorkraus.de';
$headers = "From: \"zaaReloaded\" <dk@doktorkraus.de>";
$reportId = $_POST['report_id'];
$info = print_r( $_POST, true ); // this will be a string, not an array!
$body = <<<EOF
zaaReloaded hat einen Fehler ausgelöst.
$mail->From = 'zaareloaded@nephrowiki.de';
$mail->FromName = 'zaaReloaded';
$mail->addAddress('dk@doktorkraus.de');
$mail->Subject = "[zaaReloaded] Exception $reportId";
-----
if ( $_POST['ccUser'] ) {
$validMail = filter_var( $_POST['usersMail'], FILTER_VALIDATE_EMAIL );
$validUser = filter_var( $_POST['usersName'], FILTER_SANITIZE_STRING );
if ( $validUser ) {
$validUser = "\"$validUser\" "; // space character deliberately placed
};
if ( $validMail ) {
$mail->addCC($validMail, $validUser);
};
};
Benutzerkommentar:
$info = print_r( $_POST, true );
$mail->Body = <<<EOF
zaaReloaded exception
User's comment on submission:
{$_POST['comment']}
***
-----
Technical details: $info
Technische Info: $info
--
http://zaa.nephrowiki.de
--
www.doktorkraus.de/zaareloaded
EOF;
if ($mail->send())
{
// Must return the report ID to indicate success
echo($reportId);
if ( $_POST['ccUser'] ) {
$validMail = filter_var( $_POST['usersMail'], FILTER_VALIDATE_EMAIL );
$validUser = filter_var( $_POST['usersName'], FILTER_SANITIZE_STRING );
if ( $validUser ) {
$validUser = "\"$validUser\" "; // space character deliberately placed
};
if ( $validMail ) {
$headers .= "\r\nCc: $validUser<$validMail>";
};
};
mail($to, "Exception report [$reportId]", $body, $headers);
}
else
{
echo($mail->ErrorInfo);
// =============================================================
// Begin main script
// =============================================================
if (!isset($_POST['report_id'])) {
http_response_code(400);
exit;
}
sendMail();
// Return the report ID and the issue URL to signal all is well.
$reportId = $_POST['report_id'];
$load = "{\"ReportId\": \"$reportId\", \"IssueUrl\": \"https://www.doktorkraus.de/zaareloaded\"}";
error_log( __FILE__ . ": Load = $load" );
header('Content-Type: application/json');
echo $load;