2
\$\begingroup\$

I have followed the WWWForm script reference to try to connect Unity with Mailchimp. According with the log, the form is sent without errors. Unfortunately Mailchimp did not stored any data.

This is my code:

public class EmailSendButton : MonoBehaviour {

    public GameObject emailInputText;
    private WWWForm form;

    /// <summary>
    /// In the Inspector we tell Unity to call this function when the button is clicked.
    /// </summary>
    public void onClick() {
        StartCoroutine(SendToMailChimp());
    }

    // TODO It seems to be working but Mailchimp did not store anything
    private IEnumerator SendToMailChimp() {
        form = new WWWForm();
        string email = emailInputText.GetComponent<UnityEngine.UI.Text>().text;
        form.AddField("mce-EMAIL", email); // I have also tried with: form.AddField("email", email);
        WWW w = new WWW("http://bustogames.us11.list-manage.com/subscribe/post?u=8855252b454d05c2f913c1d2b&amp;id=2ac022b22a", form);
        yield return w;

        if (!string.IsNullOrEmpty(w.error)) { print("Error sending the form: " + w.error); }
        else { print("Form sent without errors"); }
    }
}

This is the cut and paste code provided by Mailchimp:

<!-- Begin MailChimp Signup Form -->
<link href="//cdn-images.mailchimp.com/embedcode/slim-081711.css" rel="stylesheet" type="text/css">
<style type="text/css">
    #mc_embed_signup{background:#fff; clear:left; font:14px Helvetica,Arial,sans-serif; }
    /* Add your own MailChimp form style overrides in your site stylesheet or in this style block.
       We recommend moving this block and the preceding CSS link to the HEAD of your HTML file. */
</style>
<div id="mc_embed_signup">
<form action="//bustogames.us11.list-manage.com/subscribe/post?u=8855252b454d05c2f913c1d2b&amp;id=2ac022b22a" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate>
    <div id="mc_embed_signup_scroll">
    <label for="mce-EMAIL">Subscribe to our mailing list</label>
    <input type="email" value="" name="EMAIL" class="email" id="mce-EMAIL" placeholder="email address" required>
    <!-- real people should not fill this in and expect good things - do not remove this or risk form bot signups-->
    <div style="position: absolute; left: -5000px;"><input type="text" name="b_8855252b454d05c2f913c1d2b_2ac022b22a" tabindex="-1" value=""></div>
    <div class="clear"><input type="submit" value="Subscribe" name="subscribe" id="mc-embedded-subscribe" class="button"></div>
    </div>
</form>
</div>

<!--End mc_embed_signup-->
\$\endgroup\$
4
  • \$\begingroup\$ I'm sure there must be some C# SMTP implementation? \$\endgroup\$
    – Alec Teal
    Sep 29, 2015 at 15:30
  • \$\begingroup\$ Probably there is a SMTP implementation, but I have not found a way to connect to Mailchimp using SMTP. You gave me the idea of looking for other ways to connect with Mailchimp. It seems we can use JSON. I have to research abou that though: kb.mailchimp.com/api/article/how-to-manage-subscribers? \$\endgroup\$
    – chelder
    Sep 29, 2015 at 16:16
  • \$\begingroup\$ I have no idea what mailchimp is, I guess you wanted to send email right? \$\endgroup\$
    – Alec Teal
    Sep 29, 2015 at 16:43
  • \$\begingroup\$ No @AlecTeal. Mailchimp is a service that stores emails. So you can send similar emails like a newsletter to everybody at the same time ;) \$\endgroup\$
    – chelder
    Sep 29, 2015 at 17:49

1 Answer 1

1
\$\begingroup\$

I believe it is not the input id, but its name that is used as field name when a form is submitted. So I would use:

form.AddField("EMAIL", email);

Also, there seems to be a hidden input on the form provided by Mailchimp called b_8855252b454d05c2f913c1d2b_2ac022b22a, so you should also have the following line in your code:

form.AddField("b_8855252b454d05c2f913c1d2b_2ac022b22a", "");

And lastly, if the above is not sufficient, the form might require the submit button to be there, so you could also add the following:

form.AddField("subscribe", "Subscribe");

I hope this helps.

\$\endgroup\$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .