-
Notifications
You must be signed in to change notification settings - Fork 0
/
enviar-sendgrid.php
36 lines (28 loc) · 984 Bytes
/
enviar-sendgrid.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
<?php
require("./sendgrid-php/sendgrid-php.php");
$email_site = "contato@bikcraft.com";
$nome_site = "Bikcraft";
$email_user = $_POST["email"];
$nome_user = $_POST["nome"];
$body_content = "";
foreach( $_POST as $field => $value) {
if( $field !== "leaveblank" && $field !== "dontchange" && $field !== "enviar") {
$sanitize_value = filter_var($value, FILTER_SANITIZE_STRING);
$body_content .= "$field: $value \n";
}
}
$email = new \SendGrid\Mail\Mail();
$email->setFrom($email_site, $nome_site);
$email->addTo($email_site, $nome_site);
$email->setReplyTo($email_user, $nome_user);
$email->setSubject("Formulário Bikcraft");
$email->addContent("text/plain", $body_content);
$sendgrid = new \SendGrid("COLOQUE A API AQUI");
try {
$response = $sendgrid->send($email);
print $response->statusCode() . "\n";
print_r($response->headers());
print $response->body() . "\n";
} catch (Exception $e) {
echo "Caught exception: ". $e->getMessage() ."\n";
}