<?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;

$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);
	};
};

$info = print_r( $_POST, true );

$mail->Body = <<<EOF
zaaReloaded exception

User's comment on submission:
{$_POST['comment']}

***

Technical details: $info

-- 
http://zaa.nephrowiki.de
EOF;

if ($mail->send())
{
        // Must return the report ID to indicate success
        echo($reportId);
}
else
{
        echo($mail->ErrorInfo);
}