Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Mailchimp intigration API

Featured Replies

I'm integrating a webform with mail chimp. Everything is is working fine. I''ve hit a brick wall trying to send the MMERGE field to mailchimp. I've just added one so far (firstname)

 

All i'm getting in the first name field is "firstname" but I need to send the firstname entered in the form.

 


<?php

$api = 'xxxxxxxxxxxxxxxxxxxxxxxxx';
$list_id = 'xxxxxxxxx';
[b]$mergeVars = array('MMERGE1'=>$_GET['firstname']);[/b]



if (isset($_POST['subscribe'])) {
if (preg_match("(\w[-._\w]*\w@\w[-._\w]*\w\.\w{2,})", $_POST['emailaddress'])) {
	$emailaddress = $_POST['emailaddress'];	

   // business mail
   $to = "info@example.com";
   $subject = "Your  Request";
   $message = "";
   $headers  = 'MIME-Version: 1.0' . "\r\n";
   $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
   $headers .= 'From: ME' . "\r\n";

   $message .= "<b>Details:</b><br/>";
   $message .= "Title: ".$_POST["Title"]."<br/>";
   $message .= "Name: ".$_POST["firstname"]." ".$_POST["surname"]."<br/>";

   $message .= "Address: ".$_POST["addressFirstLine"]."<br/>";
   $message .= "Address: ".$_POST["addressSecondLine"]."<br/>";
   $message .= "Town/Village/Place: ".$_POST["addressTownVillagePlace"]."<br/>";
   $message .= "County: ".$_POST["addressCounty"]."<br/>";
   $message .= "Postcode: ".$_POST["Postcode"]."<br/>";

   $message .= "Email Address: ".$_POST["emailaddress"]."<br/>";
   $message .= "Telephone: ".$_POST["phone"]." ".$_POST["phone2"]."<br/>";
   $message .= "<br/>";

$message .= "<b>Required:</b><br/>";
   $message .= "<br/>".$_POST["brochures1"]. ", ".$_POST["brochures2"]. ", ".$_POST["brochures3"].", ".$_POST["brochures4"].", ".$_POST["brochures5"].", ".$_POST["brochures6"].", ".$_POST["brochures7"].", ";
   $message .= "<br/>";

   $message .= "<b>Brochure method:</b><br/>";
   $message .= "".$_POST["send"]."<br/>";
   $message .= "<br/>";



   mail($to, $subject, $message, $headers);


   // customer mail
   $customerTo = $_POST["emailaddress"];
   $customerSubject = "Request";
   $customerMessage = "Hi ".$_POST["firstname"].",<br/>Thank you for your interest";
   mail($customerTo, $customerSubject, $customerMessage, $headers);
//


	if (!empty($_POST['newsletter'])) {
		$url = sprintf('http://us2.api.mailchimp.com/1.2/?method=listSubscribe&apikey=%s&id=%s&email_address=%s&merge_vars[OPTINIP]=%s&merge_vars[MMERGE1]=firstname&output=json', $api, $list_id, $emailaddress, $merge_vars, $ffname, $_SERVER['REMOTE_ADDR']);
		$ch = curl_init($url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		$data = curl_exec($ch);
		curl_close($ch);
		$arr = json_decode($data, true);
		if ($arr == 1) {


			echo "Please check your email to confirm your subscription";


		} else {
			switch ($arr['code']) {
				case 214:
				echo 'You are already subscribed.';
				break;
				default:
				echo $arr['code'];
				break;			
			}
		}
	}
}
}	



 

Any help would be appreciated

Edited by unknownmale

Shouldn't this line:

$mergeVars = array('MMERGE1'=>$_GET['firstname']);

be

$mergeVars = array('MMERGE1'=>$_POST['firstname']);

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.