Skip to content

Instantly share code, notes, and snippets.

@Burrer
Last active December 27, 2018 09:32
Show Gist options
  • Save Burrer/711f18feb28f7bff5c0ad78cdd7fcc1d to your computer and use it in GitHub Desktop.
Save Burrer/711f18feb28f7bff5c0ad78cdd7fcc1d to your computer and use it in GitHub Desktop.
Subscription Widget: SG MC
<?php
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email = $_POST['email'];
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.sendgrid.com/v3/contactdb/recipients",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "[\n {\n \"email\": \"$email\",\n \"first_name\": \"$first_name\",\n \"last_name\": \"$last_name\"\n }\n]",
CURLOPT_HTTPHEADER => array(
"authorization: Bearer [API Key - suggest only giving marketing campaigns upload scopes]",
"cache-control: no-cache",
"content-type: application/json"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
header('Location: thanks.html');
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
?>
/* Form.html CSS, just copy and paste any where in your style.css file, or customize to fit with your domain */
form.contact p {
font-size: 15px;
padding: 0 0 15px 0;
margin: 0;
}
form.contact input, form.contact textarea {
font-family: Arial;
font-size: 15px;
margin: 0 0 20px 0;
}
form.contact textarea {
background: #f5f5f5;
padding: 5px;
border: 1px solid #bbb;
border-radius: 15px;
width: 400px;
height: 150px;
}
form.contact input {
background: #f5f5f5;
padding: 5px;
border: 1px solid #bbb;
border-radius: 15px;
}
form.contact input.send {
color: #fff;
background: #222;
border: #222;
padding: 10px 25px 10px 25px;
cursor: pointer;
}
/* End form.html's CSS */
<!-- this can be removed for own css - just keeping it in HTML for visual reference-->
<head>
<link rel="stylesheet" type="text/css" href="form.css">
</head>
<div class="section-page-landing" id="contact">
<div class="inner-section">
<div class="contain">
<center><h2>Contact Me</h2>
<form class="contact" action="contact_api.php" method="post">
<p>First Name:</p> <!-- Can choose to customize form.html inputs starting here as needed, but be sure to reference any changes in mailer.php post fields-->
<input type="text" name="first_name" />
<p>Last Name:</p>
<input type="text" name="last_name" />
<p>Email:</p>
<input type="text" name="email" /><br><br>
<input class="send" type="submit" value="Send"> <!-- Send button-->
</form></center>
</div>
</div>
</div>
<!DOCTYPE html>
<html>
<head>
<title>Thank You!</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="keywords" content="">
<meta name="author" content="">
<!-- CSS -->
<link href="assets/css/bootstrap.min.css" rel="stylesheet">
<link href="assets/css/animate.css" rel="stylesheet">
<link href="assets/css/style.css" rel="stylesheet">
<link href="assets/css/style-responsive.css" rel="stylesheet">
<link href="assets/third/font-awesome/css/font-awesome.css" rel="stylesheet">
<!-- REQUIRED FOR LANDING PAGE -->
<link href="assets/third/vegas/jquery.vegas.min.css" rel="stylesheet">
<link href="assets/third/hovericon/css/component.css" rel="stylesheet">
<body>
<div class="section-page-landing section-grey" id="services">
<div class="inner-section">
<div class="container">
<h2 class="text-center"> Aw Yis</h2><br>
<h4 class="text-center">
Thank You For Contacting Me! I Will Get Back To You As Soon As Possible.
<br><br><br><br>
<a href="index.html">HOME</a>
</h4>
</body>
</head>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment