-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmail.php
More file actions
38 lines (31 loc) · 1.05 KB
/
mail.php
File metadata and controls
38 lines (31 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = strip_tags(trim($_POST["nome"]));
$name = str_replace(array("\r","\n"),array(" "," "),$name);
$email = filter_var(trim($_POST["email"]), FILTER_SANITIZE_EMAIL);
$message = trim($_POST["mensagem"]);
$subject = $_POST["assunto"];
if ( empty($name) OR empty($message) OR !filter_var($email, FILTER_VALIDATE_EMAIL)) {
http_response_code(400);
echo "Formulário incompleto.";
exit;
}
$recipient = "eripi@ufpi.edu.br";
$email_content = $message;
$email_headers = "From: $name <$email>\r\n";
$email_headers .= "Reply-To: $name <$email>\r\n";
$email_headers .= "Return-Path: $name <$email>\r\n";
$email_headers .= "Content-Type: text/html; charset=UTF-8\r\n";
$email_headers .= "X-Mailer: PHP". phpversion();
if (mail($recipient, $subject, $email_content, $email_headers)) {
http_response_code(200);
echo "Mensagem foi enviada.";
} else {
http_response_code(500);
echo "Erro ao enviar mensagem, tente novamente.";
}
} else {
http_response_code(403);
echo "Método Http inválido.";
}
?>