Mailchimp create campaign with DrewM PHP wrapper - php

How do I create a campaign using this wrapper and pass parameters? Ive searched the internet and the documentation but their isn't enough information or example code
$mc->post('campaigns');
just returns an error. Thanks in advance.

Assuming you've authenticated, etc., you can just add in your parameters like the Mailchimp docs show:
$result = $MailChimp->post("campaigns", [
'type' => 'regular',
'recipients' => ['list_id' => 'xxx'],
'settings' => ['subject_line' => 'Your Purchase Receipt',
'reply_to' => 'orders#example.com',
'from_name' => 'Customer Service']
]);
The wrapper doesn't really do anything; it just provides a standard way to pass these arrays to Mailchimp.

Related

Realtime voice call with 2 person using nexmo/vonage

is it possible to do realtime voice call using nexmo/vonage with PHP or Javascript via web browser?
i used library called nexmo/laravel.
This sample code that i used:
$nexmo = Nexmo::calls()->create([
'to' => [[
'type' => 'phone',
'number' => '855969818674'
]],
'from' => [
'type' => 'phone',
'number' => '63282711511'
],
'answer_url' => ['https://gist.githubusercontent.com/jazz7381/d245a8f54ed318ac2cb68152929ec118/raw/6a63a20d7b1b288a84830800ab1813ebb7bac70c/ncco.json'],
'event_url' => [backpack_url('call/event')]
]);
with that code i can send text-to-speech, but how can i do realtime voice conversation person to person?
From the code you shared above, it looks like you might not have instantiated a client instance of the Nexmo PHP SDK, which is necessary to do so. You make an outbound call with an instantiated and authenticated client.
For example, first instantiate a client with the following, supplying the file path to your private key file, your application ID, your API key and your API secret. You can obtain all of those from the Dashboard
$basic = new \Nexmo\Client\Credentials\Basic('key', 'secret');
$keypair = new \Nexmo\Client\Credentials\Keypair(
file_get_contents((NEXMO_APPLICATION_PRIVATE_KEY_PATH),
NEXMO_APPLICATION_ID
);
$client = new \Nexmo\Client(new \Nexmo\Client\Credentials\Container($basic, $keypair));
Then, once you have a credentialed client, you can then invoke the $client->calls() methods on it. For example:
$client->calls()->create([
'to' => [[
'type' => 'phone',
'number' => '14843331234'
]],
'from' => [
'type' => 'phone',
'number' => '14843335555'
],
'answer_url' => ['https://example.com/answer'],
'event_url' => ['https://example.com/event'],
]);
You can find more information on using the PHP SDK on GitHub. You can also find code snippets, tutorials, and more instructions on our developer portal.

How and where to pass Variables to a campaign in MailJet?

I'm trying to autogenerate a campaign draft with MailJet api v3
I created a template on their website in MJML, simple one (templateid is $tId=829886;):
<mj-raw> {% for products in var:product %} </mj-raw>
<p>{%product.name %}</p>
<p>{%product.price%}</p>
<mj-raw>{% endfor %}</mj-raw>
I also included both [[UNSUB_LINK_IT]] and [[UNSUB_LINK_EN]] because of the locale it_IT
In my php code I'm testing with :
$tId=829886;
$products=[
["name"=>'Product1','price'=>'free'],
['name'=>'Product2','price'=>'1 mil']
];
Campaign draft
$body = [
'Locale' => "it_IT",
'Sender' => "MisterMailjet",
'SenderEmail' => "s.s***i#***.p**",
'Subject' => "Greetings from Mailjet",
'ContactsListID' => "13",
'Title' => "Friday newsletter".uniqid(),
'EditMode' => 'tool2',
'TemplateID'=>$tId,
'Variables' => [
'products' => $products
], ];
$response = $mj->post(Resources::$Campaigndraft, ['body' => $body]);
I tried passing 'Variables' to $response = $mj->post(Resources::$CampaigndraftDetailcontent, ['id' => $cId, 'body' => $body]); but I always get
Invalid json input: object ""->"TCampaignDraft" has no property
"Variables"
Can someone link or show me an example of a $Campaigndraft or $CampaigndraftDetailcontent where they pass some variables for a loop, I can't seem to find anything online. I'm not sure if it's even possible to pass vars to campaign anymore. Please any help is appreciated
Currently the advanced "Template Language" used for personalization, is only available for so called Transactional messages and not for Campaigns. Thus the /campaigndraft resource used to create the Campaign won't recognize the "Variables" or "Vars" properties used to declare the variables within an Send API Call.
Indeed in the guide here you would see that
Mailjet Template language is available for transactional messages only.
From what I know there should be a release for Template Language in Campaigns as well, but that would be with the use of Contact Properties instead of Variables.
I hope that helps.

Inline multiple images Mailgun API Batch

I am trying to pass multiple images via Mailgun's inline API-parameter. I have no problem with only one image, but when I try with multiple images - as in the code below - only the last image in the array is displayed in the email.
$template = View::make('emails.template')->render();
$result = $mgClient->sendMessage($domain, array(
'from' => $sender,
'to' => implode(',',$emailAddresses),
'subject' => '%recipient.subject%',
'text' => $messageText,
'recipient-variables' => json_encode($credentials),
'html' => $template
), array(
'inline' => array(
'path/to/image1.png',
'path/to/image2.png',
'path/to/image3.png',
'path/to/image4.png')
));
The code above works as if the last element in the array is the only element.
The documentation for sending inline images with Mailgun is found here and it's said here that "You can post multiple inline values" which means that I'm definitely doing something wrong.
Try this once:
$result = $mgClient->sendMessage($domain, array(
'from' => $sender,
'to' => implode(',',$emailAddresses),
'subject' => '%recipient.subject%',
'text' => $messageText,
'recipient-variables' => json_encode($credentials),
'html' => $template
), array(
'inline' => array(
array('path/to/image1.png'),
array('path/to/image2.png'),
array('path/to/image3.png'),
array('path/to/image4.png')
)));
Basically wrapping each image path in an array.
Also what is the contents of $template?
This was actually a recently introduced bug. A new pull request has been submitted to the official Mailgun PHP SDK, for more info see here.
So to answer the question: the code is working fine, as soon as the SDK is updated according to above pull request. For now I edited my local copy of mailgun-php accordingly and it worked fine. Many thanks to Travis Swientek on Mailgun for quick response.

Mailchimp verify subscriber email first

I use Laravel 5 to develop an app and I use Mailchimp for adding subscription. I use Mailchimp v.3 . I can make a list using this code:
$mailchimp = new Mailchimp(xxxxxxxxxxxx-xx);
$contact = [
'company' => $request['campaign'],
'address1' => $request['address'],
'city' => $request['city'],
'state' => $candidate->userCandidate->state,
'zip' => $request['zip'],
'country' => $request['country'],
'phone' => $request['phone'],
];
$campaign_details = [
'from_name' => $request['from_name'],
'from_email' => $request['from_email'],
'subject' => $request['remind_text'],
'language' => 'English'
];
$data = [
'name' => Auth::user()->name . ' Campaign',
'contact' => $contact,
'permission_reminder' => $request['remind_text'],
'campaign_defaults' => $campaign_details,
'notify_on_subscribe' => $request['from_email'],
'notify_on_unsubscribe' => $request['from_email'],
'email_type_option' => false,
'visibility' => $request['visibility'],
];
$list = $mailchimp->post('lists', $data);
I use this library drewm/mailchimp. My code on subscribing is this:
$mailchimp = new Mailchimp($api_key);
$subscriber = [
'email_type' => 'html',
'email_address' => $email,
'language' => 'English',
'status' => 'subscribed',
'merge_fields' => ['zip' => $zip]
];
$result = $mailchimp->post('lists/' . $list_id . '/members', $subscriber);
And I can successfully subscribe it. This is my question how to verify an email first before will be recorded on mailchimp list to avoid spammer. I read on mailchimp that they have DOUBLE OPT-IN method but it is only available if you use their form.
My solution is to email first on subscriber and create a link for verifying and this solution can take time. Is there another solution on this? Does Mailchimp have method to acquire this?
I don't have any idea on Mailchimp API. However, you just have to set up an email validation flow first. In this way, all emails will not be considered as "spam" in your records. Then you're free to do any email tasks without worrying if it is valid or not.
The quick answer to your question is to set the status to "pending" instead of "subscribed", but you should check out MailChimp's docs on managing subscribers with API v3 for more details.
MailboxValidator does have an easy import feature to grab your list from MailChimp for email validation purposes. Then it automatically updates your MailChimp list once the validation process is done.
https://www.mailboxvalidator.com/resources/articles/how-to-import-email-list-from-mailchimp/

MailChimp API 3.0 batch/bulk subscribe

For MailChimp API 2.0 there was a method 'batch-subscribe', to send in an array of email addresses to be added to a specific list in MailChimp.
How to implement this in the new Rest Architecture based MailChimp API 3.0?
See https://github.com/mailchimp/APIv3-examples/wiki/Overview
It says it would work with array of objects
But by the schema it only accepts an object
Schema https://us9.api.mailchimp.com/schema/3.0/Lists/Members/Collection.json
MailChimp API v3.0 is now live! and they've also added a better batch operations feature which lets you make multiple operations in just one call.
You can use below code with the help of this php wrapper for MailChimp apiV3 for the batch operations.
$data1 =array(
'email_address' => 'testingmail1#gmail.com',
'status' => 'subscribed',
'merge_fields' => array('FNAME' => 'Testing', 'LNAME' => 'Mail1'));
$data2 =
array(
'email_address' => 'testingmail2#example.com',
'status' => 'subscribed',
'merge_fields' => array('FNAME' => 'Testing', 'LNAME' => 'Mail2'));
$attributes = array(
'operations' => array(
array(
'path' => 'lists/' . $listID . '/members',
'method' => 'POST',
'body' => json_encode($data1)
),
array(
'path' => 'lists/' . $listID . '/members',
'method' => 'POST',
'body' => json_encode($data2)
),
));
$response = $MailChimp->post('batches/', $attributes);
The page you're linking to look like docs from the beta, but either way, they say that batch operations aren't yet implemented. FWIW, the real docs also list Batch Operations as a part of the roadmap, so I doubt they're done yet.
This is not an issue at the Mailchimp end. You just need to use arrays and objects properly.
Good batch subscribe example you can find here https://rudrastyh.com/wordpress/wp-users-to-mailchimp-list.html#batch_subscribe_php
Yeah. It was an issue at the Mailchimp end. We reported it and they got it fixed in a day or so.

Categories