Last active
December 28, 2015 04:20
-
-
Save prionkor/5d2249bdfd38be5d038c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <form action="kallzu-integration.php" method="post"> | |
| <p><input type="text" name="name" placeholder="your name here" required="required"></p> | |
| <p><input type="email" name="email" placeholder="your email here" required="required"></p> | |
| <p><input type="text" name="phone" placeholder="your phone number here" required="required"></p> | |
| <p><textarea name="message" placeholder="your message"></textarea></p> | |
| <p><button type="submit" name="submit_to_kallzu">Submit</button></p> | |
| <!-- You must use captcha to protect spam --> | |
| </form> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // This php script gives an example of sending data to Kallzu server for email lead capture | |
| /* | |
| NOTE: | |
| 1. Data isn't sanitized for the sake of simplicity | |
| 2. Data isn't validated for the sake of simplicity | |
| 3. Make sure you use captcha to protect yourself with spam messages | |
| */ | |
| // Server expects POST request and returns json response | |
| $endpoint = "http://kallzu2.kallzu.com/email-leads.php"; | |
| // only message key is optional. All other values are required and server will reject if any value is empty or not set. | |
| // So, put the validation accordingly | |
| $data = array( | |
| 'api_key' => 'xxxx-xxxxx-xxxxx-xxxxx-xxxxx', // put the email lead tracker key you have generated from http://app.kallzu.com/email-leads/ | |
| 'domain' => 'mysite.com' | |
| 'campaign_id' => 1 // add your kallzu campaign id here | |
| ); | |
| if(!isset($_POST['submit_to_kallzu'])){ | |
| die('form not sent'); | |
| } | |
| if(isset($_POST['campaign_id']) && !empty($_POST['campaign_id'])){ | |
| $data['campaign_id'] = (int) $_POST['campaign_id']; | |
| }else{ | |
| die('No campaign id provided'); | |
| } | |
| if(isset($_POST['name']) && !empty($_POST['name'])){ | |
| $data['name'] = $_POST['name']; | |
| }else{ | |
| die('please enter name'); | |
| } | |
| if(isset($_POST['email']) && !empty($_POST['email'])){ | |
| $data['email'] = $_POST['email']; | |
| }else{ | |
| die('please enter email'); | |
| } | |
| if(isset($_POST['phone']) && !empty($_POST['phone'])){ | |
| $data['phone'] = $_POST['phone']; | |
| }else{ | |
| die('please enter phone'); | |
| } | |
| if(isset($_POST['message']) && !empty($_POST['message'])){ | |
| $data['message'] = $_POST['message']; | |
| } | |
| $response = send_http_request($endpoint, $data); | |
| // use the $response variable to print error or success message. | |
| function send_http_request($serverUrl, $params, $headers=NULL) { | |
| //initialise a CURL session | |
| $connection = curl_init(); | |
| //set the server we are using (could be Sandbox or Production server) | |
| curl_setopt($connection, CURLOPT_URL, $serverUrl); | |
| //stop CURL from verifying the peer's certificate | |
| curl_setopt($connection, CURLOPT_SSL_VERIFYPEER, 0); | |
| curl_setopt($connection, CURLOPT_SSL_VERIFYHOST, 0); | |
| //set the headers using the array of headers | |
| if ($headers) | |
| curl_setopt($connection, CURLOPT_HTTPHEADER, $headers); | |
| //set method as POST | |
| curl_setopt($connection, CURLOPT_POST, 1); | |
| //set the body of the request | |
| if ($params) | |
| curl_setopt($connection, CURLOPT_POSTFIELDS, http_build_query($params)); | |
| //set it to return the transfer as a string from curl_exec | |
| curl_setopt($connection, CURLOPT_RETURNTRANSFER, 1); | |
| //Send the Request | |
| $response = curl_exec($connection); | |
| //close the connection | |
| curl_close($connection); | |
| //return the response | |
| return $response; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment