[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]