-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsend_mail.php
More file actions
118 lines (100 loc) · 2.56 KB
/
send_mail.php
File metadata and controls
118 lines (100 loc) · 2.56 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
require 'lib/phpmailer/PHPMailerAutoload.php';
require 'partes/config.php';
if (!empty($_POST)) {
$nome = $_POST['nome'];
$email = $_POST['email'];
$assunto = $_POST['assunto'];
$mensagem = $_POST['mensagem'];
$corpo_mensagem_html = '
<h3>Nome: <small>'.$nome.'</small></h3>
<h3>Telefone: <small>'.$assunto.'</small></h3>
<h3>E-mail: <small>'.$email.'</small></h3>
<h3>Mensagem:</h3>
<p>'.$mensagem.'</p>
';
$corpo_mensagem = '
Nome: '.$nome.'
Assunto: '.$assunto.'
E-mail: '.$email.'
Mensagem: '.$mensagem;
/*
$data = array(
'success' => false,
'errors' => array()
);
$inputs = $_POST;
foreach ($inputs as $key => $value) {
switch($key) {
case "nome":
if (strlen($value) < 6) {
$msg = "O campo nome não pode estar vazio e tem que ter mais de 6 caracteres.";
}
break;
case "email":
if (!filter_var($value, FILTER_VALIDATE_EMAIL)) {
$msg = "Você deve fornecer um e-mail válido.";
}
break;
case "assunto":
if (strlen($value) < 6) {
$msg = "O campo assunto não pode estar vazio.";
}
break;
case "mensagem":
if (strlen($value) < 30) {
$msg = "Sua mensagem é muito curta.";
}
break;
default:
$msg = "Campos inválidos.";
break;
}
//If there is an error, add it to the errors array with the field id
if (!empty($msg)) {
$data['errors'][] = array(
'msg' => $msg,
'campo' => $key
);
}
}
//Validation over, was it successful?
if (empty($data['errors'])) {
$data['success'] = true;*/
/*
}
header("Content-Type: application/json; charset=UTF-8");
echo json_encode((object)$data);*/
if (!empty($nome) && !empty($assunto) && !empty($email) && !empty($mensagem) ) {
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = $smtp_server_mail;
$mail->SMTPAuth = true;
$mail->Username = $usuario_mail;
$mail->Password = $senha_mail;
$mail->Port = 587;
//$mail->SMTPSecure = 'ssl';
$mail->CharSet = 'UTF-8';
$mail->From = $usuario_mail;
$mail->FromName = $cliente;
$mail->addAddress($destinatario);
$mail->isHTML(true);
$mail->Subject = 'Fale Conosco (Site)';
$mail->Body = $corpo_mensagem_html;
$mail->AltBody = $corpo_mensagem;
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
$response = array("success" => true);
echo json_encode($response);
}
} else {
$response = array("error" => true);
echo json_encode($response);
}
} else {
$redirect = $baseURL . '/nao-encontrado';
header("location:$redirect");
}
?>