Code Monkey home page Code Monkey logo

Comments (3)

dustingraham avatar dustingraham commented on May 30, 2024 1

Thanks @Bogardo I didn't see $message->recipientVariables in the documentation so I was also wondering. I see it in the code now.

Might consider returning $this so we can chain functions.

from mailgun.

Bogardo avatar Bogardo commented on May 30, 2024

The best way to fix this is by using recipient variables.
From the Mailgun Documentation:

Batch Sending

Mailgun supports the ability send to a group of recipients through a single API call.

This is achieved by either:

  • Using Batch Sending by specifying multiple recipient email addresses as to parameters and using Recipient Variables.
  • Using Mailing Lists with Template Variables.

Warning It is important when using Batch Sending to also use Recipient Variables. This tells Mailgun to send each recipient an individual email with only their email in the to field. If they are not used, all recipients’ email addresses will show up in the to field for each recipient.

Take special note of the last (bold) paragraph.

Example:

Mailgun::send(emails.mudrush', $data, function($message)
{
    $message->to([
        '[email protected]',
        '[email protected]',
        '[email protected]',
    ]);
    $message->recipientVariables([
        '[email protected]' => ['name' => 'John Doe'],
        '[email protected]' => ['name' => 'Foo Bar'],
        '[email protected]' => ['name' => 'Baz Bar'],
    ]);
});

Another option would probably be to use the bcc() method but I recommend using the recipient variables.

Mailgun::send('emails.mudrush', $data, function($message) use($users)
{
    $message->subject('Last day to WIN free passes to The Mud Rush');
    $message->bcc($users);
});

Simmilar issues:

Issue using To foreach loop #31
Support for recipient variables #34

from mailgun.

dukesnuz avatar dukesnuz commented on May 30, 2024

I am trying to accomplish same as @dustingraham . I want to use recipientVariables
My question is:
If all email addresses are in and array, How do I pass them into here?

        '[email protected]',
        '[email protected]',
        '[email protected]',
    ]);
    $message->recipientVariables([
        '[email protected]' => ['name' => 'John Doe'],
        '[email protected]' => ['name' => 'Foo Bar'],
        '[email protected]' => ['name' => 'Baz Bar'],
    ]);


Say I have something like this:
$e = array_chunk($emails, 900);

Mailgun::send(emails.mudrush', $data, function($message)
{
    $message->to([
      (How would I pass the email addresses in here?)
        '[email protected]', 
        '[email protected]',
        '[email protected]',
    ]);
    $message->recipientVariables([
     (How would I pass the recipient variables in here?)
        '[email protected]' => ['name' => 'John Doe'],
        '[email protected]' => ['name' => 'Foo Bar'],
        '[email protected]' => ['name' => 'Baz Bar'],
    ]);
});```

I have been trying to figure this out for a long time.
Thank you very much. 

from mailgun.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.