Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Deekshith's avatar

Sending bulk email using sendgrid

Hi Guys, Please help me,

I have a user management application and i have around 15k users registered on our website. and we have a simple blog application designed using laravel and I want to send email to all registered users once i post any updates in the blog. I am using sendgrid for this, but whenever I tried to send email, it is taking too much time in a loop and sometimes it gives timeout error. is there any way I can achieve this at high speed? and I need to hide all recipients email address. i know by using bcc we can hide all emails but need clarification regarding this.

Here is the sample code:

//converted email array to chunks

$recipient_chunks = array_chunk($email_array, 999);

//loop over user email address

foreach ($recipient_chunks as $user) {

Mail::queue('emails.updates_template',$email_data,function($message) use($email_data,$user) { $message->bcc($user)->subject('Latest Updates'); });

}

0 likes
3 replies
aurawindsurfing's avatar

Hi,

TL&TR - Do not use your server to send bulk mail.

You should be able to utilise their API or any other provider like sendinblue.com, for instance, to create an HTML campaign then upload your list of recipients and then schedule it to send.

This will be done in a few seconds and then they worry about the rest.

Hope it helps!

Deekshith's avatar

Thanks for the reply, But in my case I have a blog application once new article posted then it should send bulk email for all registered emails. This is dynamic. I am experiencing some problem in mail queues. It seems your point will be valid if my user database is fixed but what if my user database will be increased? And I am using sendgrid to send emails.

md's avatar

Here's some examples on how to use SendGrid:

https://github.com/sendgrid/sendgrid-php#hello-email

https://sendgrid.com/docs/API_Reference/Web_API_v3/Mail/index.html

$mail['personalizations'][] = [
    'to' => [
        [
            'name' => $name,
            'email' => $email
        ]
    ],
    'subject' => 'new blog article'
];
$mail['from'] = [
    'name' => 'name of site',
    'email' => '[email protected]'
];
$mail['content'][] = ['type' => 'text/html', 'value' => 'html email'];

$sendGridAPI->send($mail);

Please or to participate in this conversation.