Skip to content

Create Sendy html code + google recaptcha for website homepage

edited November 2017 in Questions

I've tried posting a job request on Fiverr and haven't had much luck.
I run an ecommerce store and am looking to add my sendy sign up form to the homepage. I also want Google Recaptcha since the last time we put a form without recaptcha it got bombarded by SPAM bots. I already registered my site with recaptcha and am using it with my stores built in contact form but I want to use it with Sendy's contact form code.

Anyone know how to do this or would be willing to do this for like $50.00. I know it's not a huge job and fairly simple but I just don't know how to do it.

Comments

  • I am very much interested if some one is willing to share the code for this..... Recenty im spammed like hell and a reCAPTCHA is really needed. I think everyone can use this maybe integrate this in Sendy?

  • Hi I have yet to get Sendy working but the following should work:

    Step 1 register a domain and grab site key and secret key

    https://www.google.com/recaptcha/admin#list

    Step 2 Modify the following php page to suit yourself. We are using the sendy api here.

    <?php

    //-------------------------- All these need to be set ------------------------//

    $recaptcha_secret = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; // Your recapture secret key

    $your_installation_url = 'https://bbbbbbbbbbbbbbbbbbbbbbbbb.com/ar'; //Your Sendy installation (without the trailing slash)

    $list = 'ccccccccccccccccccccccccccccccccccccccc'; //Can be retrieved from "View all lists" page

    $success_url = 'http://ddddddddddddddddddddd.com'; //URL user will be redirected to if successfully subscribed

    //---------------------------------------------------------------------------//



    if($_SERVER["REQUEST_METHOD"] === "POST")

    {

    $response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$recaptcha_secret."&response=".$_POST['g-recaptcha-response']);

    $response = json_decode($response, true);

    if($response["success"] === true)

    {

    //POST variables

    $name = $_POST['name'];

    $email = $_POST['email'];

    $boolean = 'true';

    //Subscribe

    $postdata = http_build_query(

    array(

    'name' => $name,

    'email' => $email,

    'list' => $list,

    'boolean' => 'true'

    )

    );

    $opts = array('http' => array('method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => $postdata));

    $context = stream_context_create($opts);

    $result = file_get_contents($your_installation_url.'/subscribe', false, $context);



    //Should really check result contents before redirect

    if($result){

    header("Location: $success_url");

    }

    }

    else

    {

    echo "<center>You are possibly a robot</center>";

    }

    }

    else{

    ?>

    <!doctype html>

    <html>

    <head>

    <title>Sendy reCAPTCHA demo</title>

    <style>

    input{

    width:300px;

    font-size:22px;

    }

    </style>

    <script src='https://www.google.com/recaptcha/api.js'></script&gt;

    </head>

    <body>

    <center>

    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" accept-charset="utf-8">

    <label for="name">Name</label>

    <input type="text" name="name" required /><br/>

    <label for="email">Email</label>

    <input type="text" name="email" required /><br/>

    <!-- The recapture site key needs to be set -->

    <div class="g-recaptcha" data-sitekey="eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"></div>

    <input type="submit" value="Let Me In!" />

    </form>

    </center>

    </body>

    </html>

    <?php

    }

    ?>

This discussion has been closed.