-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathenvia-contato.php
50 lines (39 loc) · 1.31 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
47
48
49
50
<?php
session_start();
$nome = $_POST["nome"];
$email = $_POST["email"];
$mensagem = $_POST["mensagem"];
require_once("PHPMailer.php");
require_once 'OAuth.php';
require_once 'POP3.php';
require_once 'SMTP.php';
require_once 'Exception.php';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
$mail = new PHPMailer(true);
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->SMTPSecure = 'ssl';
$mail->SMTPAuth = true;
$mail->Username = "[email protected]";
$mail->Password = "";
#quem está mandando email
$mail->setFrom("[email protected]", "Alura Curso PHP e MySQL");
#quem esta recebendo o email
$mail->addAddress("[email protected]");
#assunto da mensagem
$mail->Subject = "Email de contato da loja";
#mensagem como HTML
$mail->msgHTML("<html>de: {$nome}<br/>email: {$email}<br/>mensagem: {$mensagem}</html>");
#mensagem como TXT
$mail->AltBody = "de: {$nome}\nemail:{$email}\nmensagem: {$mensagem}";
$mail->SMTPOptions = ['ssl' => ['verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true]];
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();