<?php
include('/home/devworks/public_html/auanews/config/auanews.config.php');

require_once(DIR_BASE.'phpmailer/class.phpmailer.php');

$recaptcha_secret = "6LdRLNYpAAAAAHN8aCjfVOAStxMkiG67RjX9GLe-";
$recaptcha_response = $_POST['g-recaptcha-response'];

$url = 'https://www.google.com/recaptcha/api/siteverify';
$data = array(
    'secret' => $recaptcha_secret,
    'response' => $recaptcha_response
);

$options = array(
    'http' => array(
        'header'  => "Content-type: application/x-www-form-urlencoded\r\n",
        'method'  => 'POST',
        'content' => http_build_query($data)
    )
);
$context  = stream_context_create($options);
$result = file_get_contents($url, false, $context);
$response = json_decode($result);

if ($response->success) {
$de = GUSER;
$para = $_POST['email'];
$de_nome = "Site: AUA News";
$assunto = "[Solicitacao de Informacoes]";
$corpo = '<p align="center"><table border="0" width="80%">';
$corpo .= '<tr><td width="100%" height="100px" align="center" bgcolor="#f0f0f0"><br><img src="'.URL_BASE.'/src/assets/images/logo_aua_news.png" height="85px"><br><br><font color="#1b8790" size="6">Contato no Site AUA News in Portuguese</font><br><br></td></tr>';
$corpo .= '<td colspan="2" align="center" valign="center" bgcolor="#ffffff"><img src="'.URL_BASE.'/src/assets/images/lineH.jpg" width="100%" height="14px"></td>';
$corpo .= '<tr><td width="100%" height="200px" align="center" valign="center" bgcolor="#ffffff"><font color="#1b8790"><b>Nome: </b>'.$_POST['nome'].';<br><b>E-mail: </b>'.$_POST['email'].';<br><b>N&uacute;mero de Telefone: </b>'.$_POST['telefone'].';<br><b>Mensagem:</b><br>'.$_POST['mensagem'].'</font></td></tr>';
$corpo .= '</table></p>';

function smtpmailer($para, $de, $de_nome, $assunto, $corpo) { 
	global $error;
	$mail = new PHPMailer();
	$mail->IsSMTP();					// Ativar SMTP
	$mail->IsHTML(true);
	$mail->SMTPDebug = 1;				// Debugar: 1 = erros e mensagens, 2 = mensagens apenas
	$mail->SMTPAuth = true;				// Autenticação ativada
	$mail->SMTPSecure = 'ssl';			// SSL REQUERIDO pelo GMail
	$mail->Host = 'smtp.gmail.com';		// SMTP utilizado
	$mail->Port = 465;  				// A porta 587 deverá estar aberta em seu servidor
	$mail->Username = GUSER;
	$mail->Password = GPWD;
	$mail->SetFrom($de, $de_nome);
	$mail->addReplyTo($de, $de_nome);
	$mail->addBCC('contato@auanews.com.br', 'Contato do Site AUA News');
	$mail->Subject = $assunto;
	$mail->Body = $corpo;
	$mail->AddAddress($para);
	if(!$mail->Send()) {
		$error = 'Mail error: '.$mail->ErrorInfo; 
		return false;
	} else {
		$error = 'Mensagem enviada!';
		return true;
	}
}

if (smtpmailer($_POST['email'], GUSER, $de_nome, $assunto, $corpo)) {}

?>
<meta http-equiv="refresh" content="0;url=<?php echo URL_BASE.'contato/ok'; ?>">
<?php
}else {
?>
<meta http-equiv="refresh" content="0;url=<?php echo URL_BASE.'contato/nok'; ?>">
<?php
}
?>