<?
require_once 'lib/phpmailer/class.phpmailer.php';
$mail = new PHPMailer(true); //defaults to using php "mail()"; the true param means it will throw exceptions on errors, which we need to catch
try {
	$body = '<b>Name :</b> '.$_POST['name'].'<br>';
	$body .= '<b>Message :</b><br> '.$_POST['message'].'<br>';
	$altBody = "Name: ".$_POST['name']." \n";
	$mail->CharSet = "UTF-8";
	$mail->IsHTML(true);
	$mail->AddReplyTo('tallinn@amrop.com');
	$mail->AddAddress('tallinn@amrop.com');
	$mail->SetFrom('tallinn@amrop.com');
	$mail->Subject = 'Amrop.ee candidate form';
	$mail->AltBody = $altBody;
	$mail->Body = $body;
	$mail->AddAttachment($_FILES[0]['tmp_name'], $_FILES[0]['name'], $encoding = "base64",$_FILES[0]['type']);
	if ($_FILES[1]['error']=='0') {
	$mail->AddAttachment($_FILES[1]['tmp_name'], $_FILES[1]['name'], $encoding = "base64",$_FILES[1]['type']);
	}
		if($mail->Send()){
		echo "1";
	}
} catch (phpmailerException $e) {
	echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
	echo $e->getMessage(); //Boring error messages from anything else!
}
?>