Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation: fix "Send Multiple Emails to Multiple Recipients"? #1040

Open
quentin-st opened this issue Mar 22, 2021 · 1 comment
Open
Labels
status: help wanted requesting help from the community type: bug bug in the library

Comments

@quentin-st
Copy link

Issue Summary

The "Send Multiple Emails to Multiple Recipients" documentation section basically uses this to demonstrate sending an email to multiple recipients:

new Mail(
    $from,
    [new To("[email protected]"), new To("[email protected]")],
    // ...
);

In our use case (no substitution, same body for everyone, meaning to send a separate email to each recipient individually), this lead to sending a single email with everyone in the "to" recipients list.

The right way to achieve this is to use create N Personalizations:

$email = new Mail(
    new From(self::MAIL_FROM, self::FROM_NAME),
    null,
    new Subject($subject),
    $plainTextContent,
    $htmlContent
);

// Add recipients
foreach ($emails as $emailAddress) {
    // Note: "To" constructor may throw an exception when encountering an invalid email.
    try {
        $personalization = new Personalization();
        $personalization
            ->addTo(new To($emailAddress));

        $email->addPersonalization($personalization);
    } catch (TypeException $ex) {
        continue;
    }
}

Are mails separately sent only if there is at least one substitution? Shouldn't we update the documentation to add a warning if that's the case?

Waiting for feedback before opening a PR to update the documentation!

Steps to Reproduce

  1. Try to send n emails to n recipients
  2. Use the example in the documentation (->addTo(new To($email)))
  3. Notice that a single mail is sent, with n recipients instead

Technical details:

  • sendgrid-php version: latest
  • php version: php7.4
@thinkingserious
Copy link
Contributor

Hello @chteuchteu,

Thank you for taking the time to raise this issue!

I don't think for this use case that we should only create personalizations in the case of substitutions.

Looking at the tests, it seems we did not check for the case when no substitutions are present :(

This issue has been added to our internal backlog to be prioritized. Pull requests and +1s on the issue summary will help it move up the backlog.

With best regards,

Elmer

@thinkingserious thinkingserious added help wanted status: help wanted requesting help from the community type: bug bug in the library labels Mar 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: help wanted requesting help from the community type: bug bug in the library
Projects
None yet
Development

No branches or pull requests

3 participants