Adding Multiple Recipients using Sendgrid marketing Email in PHP
Get the solution ↓↓↓Hi I am using Sendgrid marketing email API to send bulk of emails.Here i need to add multiple recipients in the list. I have seen lots of answers but i am not clear with any answer. This is the code I'm using to add single email to the list.
$data=array('email'=>'[email protected]',
'name'=>'XXXXX',
);
$email_add_data=array(
'api_user'=>$user,
'api_key'=>$password,
'list'=>$list_name,
'data'=> json_encode($data)
);
In the above code, how can i change the data array, so that I can be able to add multiple email recipients address
Answer
Solution:
You would pretty much need a&data[]=
param for each recipient you need added to your list. That's why you'd have to loop through your data, like this:
$email = array('[email protected]','[email protected]');
$name = array('andrei1','andrei2');
for($i=0;$i<count($email);$i++)
{
$data[] = json_encode(array('email' => $email[$i],
'name' => $name[$i]
));
}
$url = 'http://api.sendgrid.com/';
for($i=0;$i<count($data);$i++){
$params = array(
'api_user' => 'SENDGRID_USERNAME',
'api_key' => 'SENDGRID_PASSWORD',
'list' => 'Test list',
'data' => $data[$i]
);
$request = $url.'api/newsletter/lists/email/add.json';
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: installation failed, reverting ./composer.json and ./composer.lock to their original content
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.