Logo Hardware.com.br
Mariane Müller
Mariane Müll... Novo Membro Registrado
2 Mensagens 0 Curtidas

PHP - Onde está o erro?

#1 Por Mariane Müll... 09/10/2014 - 17:13
Tô enfrentando problemas com um formulário de contato de um site. Todos os dados são preenchidos corretamente, mas acusa erro e não envia o e-mail de contato. Já tentei de tudo e mesmo assim, não consigo. O código está aí embaixo, o que tem de errado?!

[php]
<?
if(!function_exists('IsEmailSyntaxValid')) {
function IsEmailSyntaxValid($addr) {
list($local, $domain) = explode("@", $addr);
$pattern_local = '^([0-9a-z]*([-|_]?[0-9a-z] )*)(([-|_]?)\.([-|_]?)[0-9a-z]*([-|_]?[0-9a-z] ) )*([-|_]?)$^';
$pattern_domain = '^([0-9a-z] ([-]?[0-9a-z] )*)(([-]?)\.([-]?)[0-9a-z]*([-]?[0-9a-z] ) )*\.[a-z]{2,4}$^';
$match_local = preg_match($pattern_local, $local);
$match_domain = preg_match($pattern_domain, $domain);
if ($match_local && $match_domain)
return 1;
else
return 0;
}
}
if($_POST['enviar'] == 'enviar') {
$style = 'erro';
if($_POST['nome'] !='' && $_POST['mensagem'] !='' && IsEmailSyntaxValid($_POST['email'])) {
require_once('phpmailer/class.phpmailer.php');
$mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch
//$mail->IsSMTP(); // telling the class to use SMTP
$mail->IsHTML(true);
try {
//$mail->SMTPDebug = 2; // enables SMTP debug information (for testing)

/*
$mail->SMTPAuth = true;
$mail->Host = "******"; // sets GMAIL as the SMTP server
$mail->Port = 587; // set the SMTP port for the GMAIL server
$mail->Username = "******"; // GMAIL username
$mail->Password = "******"; // GMAIL password
*/

$mail->SMTPAuth = false;

$mail->AddAddress('******');
$mail->SetFrom('*******', '***');
//$mail->AddBcc('******');

//$mail->Sender = "******";
$mail->IsHTML(true);
$mail->Subject = 'Contato pelo site: '.$_POST['assunto']; // Assunto do e-mail
$mail->Body = "

Contato pelo Site:

Nome: ".strip_tags($_POST['nome'])."
E-mail: ".strip_tags($_POST['email'])."
Telefone: ".strip_tags($_POST['telefone'])."
Mensagem: ".strip_tags($_POST['mensagem'])."
";
$mail->Send();
$style = 'sucesso';
unset($_POST);
$msg = "Sua mensagem foi enviada com sucesso!";
} catch (phpmailerException $e) {
//echo $e->errorMessage(); //Pretty error messages from PHPMailer
$style = 'erro';
$msg = "Não foi possível enviar sua mensagem. Por favor, tente novamente. ".$e->errorMessage().' '.$mail->ErrorInfo;
} catch (Exception $e) {
//echo $e->getMessage(); //Boring error messages from anything else!
$style = 'erro';
$msg = "Não foi possível enviar sua mensagem. Por favor, tente novamente. ".$e->errorMessage().' '.$mail->ErrorInfo;
}

}else{
$style = 'alerta';
$msg = "Por favor, preencha todos os campos corretamente.";
}
}
?>



Nome:
E-mail:
Telefone:
Assunto:







Mensagem:



 



 


[/php]
© 1999-2024 Hardware.com.br. Todos os direitos reservados.
Imagem do Modal