Created
May 25, 2011 22:12
-
-
Save irae/992112 to your computer and use it in GitHub Desktop.
Simple mail send.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// top of file | |
function mail_utf8($to, $subject, $message, $header) { | |
$header_ = 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/plain; charset=UTF-8' . "\r\n"; | |
$subject = "[Site Java2G] " . $subject; | |
$message = $message . "\r\n\r\n-- Mensagem enviada através do site\r\n\r\n"; | |
mail($to, '=?UTF-8?B?'.base64_encode($subject).'?=', $message, $header_ . $header); | |
} | |
if($_POST['name'] || $_POST['email'] || $_POST['subject'] || $_POST['message']) { | |
if($_POST['name'] && $_POST['email'] && $_POST['subject'] && $_POST['message']) { | |
mail_utf8('[email protected]', $_POST['subject'], $_POST['message'], "From: \"" . $_POST['name'] . "\" <" . $_POST['email'] .">"); | |
setcookie("name","",time()-3600); | |
setcookie("email","",time()-3600); | |
setcookie("subject","",time()-3600); | |
setcookie("message","",time()-3600); | |
setcookie("error", "Seu e-mail foi enviado com sucesso. Obrigado.", time()+1); | |
} else { | |
setcookie("error", "Informações insuficientes pra enviar e-mail, por favor preencha todos os campos.", time()+1); | |
if($_POST['name']) { | |
setcookie("name", $_POST['name'], time()+3600); | |
} | |
if($_POST['email']) { | |
setcookie("email", $_POST['email'], time()+3600); | |
} | |
if($_POST['subject']) { | |
setcookie("subject", $_POST['subject'], time()+3600); | |
} | |
if($_POST['message']) { | |
setcookie("message", $_POST['message'], time()+3600); | |
} | |
} | |
header('Location: ' . $_SERVER['HTTP_REFERER']); | |
} | |
?> | |
<!doctype html> | |
<!-- head here --> | |
<body> | |
<?php if($_COOKIE['error']) { ?> | |
<div id="errorMessage" onclick="document.location.reload()"><?php echo $_COOKIE['error']; ?></div> | |
<?php } ?> | |
<!-- all html here --> | |
<form method="post" action="./"> | |
<p><input placeholder="NOME" type="text" name="name" value="<?php if($_COOKIE['name']) { echo $_COOKIE['name']; } ?>"></p> | |
<!-- more html --> | |
<?php if($_COOKIE['error']) { ?> | |
<script type="text/javascript"> | |
function findPos(obj) { | |
var curtop = 0; | |
if (obj.offsetParent) { | |
do { | |
curtop += obj.offsetTop; | |
} while (obj = obj.offsetParent); | |
return [curtop]; | |
} | |
} | |
window.scroll(0,findPos(document.getElementById('contact'))-20); | |
</script> | |
<?php } ?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment