Mailchimp verify subscriber email first - php

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/

Related

Laravel Stripe Setup

okay, this is my first time to ask a question here so please give grace if it's not very clear. Anyway, I have this code in Laravel Billing.php.
Is this correct? Whenever a new customer is created, it doesn't have it's user email address but instead this unknown#domain.com was assigned to the user.
This was set by my previous developer. But ever since we hired him for just simple fix, we've had numerous issues with the site.
$stripeCustomer = StripeCustomer::create([
'email' => $currentCustomer->email ? $currentCustomer->email : 'unknown#domain.com',
'description' => $company->name,
'metadata' => [
'company_id' => $company->id,
'card_owner_email' => $currentCustomer->email ? $currentCustomer->email : false,
'company_name' => $company->name,
],
]);
You can remove customer email from the StripeCustomer when creating since stripe API said that email field of customer is optional. Here is the reference link
Here what you should fix:
$customerObject = [
'description' => $company->name,
'metadata' => [
'company_id' => $company->id,
'company_name' => $company->name,
],
];
if ($currentCustomer->email) {
$customerMetadata["metadata"]["card_owner_email"] = $currentCustomer->email;
$customerObject["email"] = $currentCustomer->email;
}
$stripeCustomer = StripeCustomer::create($customerObject);

How to create an event in a "Group Calendar" using MS Graph API (PHP plugin)

How to create an event in a "Group Calendar" using the MS Graph APIs?
This is only possible using delegated permission from a Work or School Account.
Would you please share the code to achieve that (using the PHP - new Graph())?
Is it possible to do it completely silently, or login or consent pop-ups are involved?
HideAndSeek says he did it in the post: Microsoft Graph API: Group Calendar Events created by API are not sent to users Calendar but he does not share the code or explained how he did it.
Thanks
To use APIs that only support delegated permissions, authentication + user consent is required. Below is a code sample assuming the access token variable is acquired with delegated permissions. I am using MS Graph PHP SDK
$accessToken = 'eyJ0...';
$graph = new Graph();
$graph->setAccessToken($accessToken);
$attendees = [];
array_push($attendees, [
'emailAddress' => [
'address' => 'user#domain.com',
'name' => 'Name'
],
'type' => 'required'
]);
$newEvent = [
'subject' => 'Sample Event Subject',
'attendees' => $attendees,
'start' => [
'dateTime' => '2021-05-12T22:00:00',
'timeZone' => 'Pacific Standard Time'
],
'end' => [
'dateTime' => '2021-05-12T23:00:00',
'timeZone' => 'Pacific Standard Time'
],
'body' => [
"contentType" => "HTML",
"content" => "Chat about new hire"
]
];
$response = $graph->createRequest('POST', '/groups/group-id/calendar/events')
->attachBody($newEvent)
->setReturnType(Model\Event::class)
->execute();
echo "Created event - {$response->getSubject()}.";
Here is a complete example that will help you get started. The Guide is here

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.

Mailchimp create campaign with DrewM PHP wrapper

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.

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