Skip to content

Instantly share code, notes, and snippets.

@woodyalan
Created November 13, 2019 13:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save woodyalan/069484b9bf6ced34e21f095967d5dbea to your computer and use it in GitHub Desktop.
Save woodyalan/069484b9bf6ced34e21f095967d5dbea to your computer and use it in GitHub Desktop.
<?php
require_once 'autoload.php';
$content = trim(file_get_contents("php://input"));
$decoded = json_decode($content, true);
extract($decoded);
$empresa = new \conteudoSite\Empresa();
$mail = new \SendGrid\Mail\Mail();
$mail->setFrom($email, $nome);
$mail->setReplyTo($email, $nome);
$mail->setSubject("Formulário de Contato - " . $empresa->getNome());
$mail->addTo($empresa->getEmail(), $empresa->getNome());
$mail->setTemplateId('4413a27b-3bac-497c-bec4-8d6b1aad205b');
$sendgrid = new \SendGrid('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');
$body = "<p><strong>Nome:</strong> $nome</p>";
$body .= "<p><strong>E-mail:</strong> $email</p>";
$body .= "<p><strong>Telefone:</strong> <a href='tel:$telefone'>$telefone</a></p>";
$body .= "<p><strong>Mensagem:</strong> $mensagem</p>";
$mail->addContent("text/html", $body);
$response['success'] = false;
try {
$response = $sendgrid->send($mail);
if($response->statusCode() == 200) {
$response['success'] = true;
}
} catch (Exception $e) {
http_response_code(500);
$response['message'] = $e->getMessage();
}
echo json_encode($response);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment