forked from carloseduardoweb/curso-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenvia-contato.php
46 lines (43 loc) · 1.5 KB
/
envia-contato.php
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
<?php
session_start();
require_once "util.php";
require_once ".propriedades-smtp.php";
require_once "class/PHPMailerAutoload.php";
$nome = getReqParamAndDestroy($_POST, 'nome');
$email = getReqParamAndDestroy($_POST, 'email');
$assunto = getReqParamAndDestroy($_POST, 'assunto');
$msg = getReqParamAndDestroy($_POST, 'msg');
$mail = new PHPMailer();
$mail->isSMTP();
//$mail->SMTPDebug = 2;
$mail->Host = $propriedadesSMTP['host'];
$mail->Port = $propriedadesSMTP['port'];
$mail->Username = $propriedadesSMTP['username'];
$mail->Password = $propriedadesSMTP['password'];
$mail->SMTPSecure = $propriedadesSMTP['crypto-protocol'];
$mail->SMTPAuth = true;
$mail->setFrom($propriedadesSMTP['from']);
$mail->addReplyTo($email, $nome);
$mail->addAddress($propriedadesSMTP['from']);
$mail->Subject = $assunto;
$mail->msgHTML("<html>
<body>
de: {$nome}<br />
email: {$email}<br /><br />
assunto: {$assunto}<br />
mensagem: {$msg}
</body>
</html>");
$mail->AltBody = "de: " . $nome . "\n" .
"email: " . $email . "\n\n" .
"assunto: " . $assunto . "\n" .
"mensagem: " . $msg;
//$mail->addAttachment('images/phpmailer_mini.png');
if ($mail->send()) {
$_SESSION['success'] = "Mensagem enviada com sucesso!";
header("Location: index.php");
} else {
$_SESSION['danger'] = "Erro ao enviar mensagem: " . $mail->ErrorInfo;
header("Location: contato.php");
}
die();