5

I'm using Mailjet Send API.

I can send emails by using this part ofcode :

$body = [
          'Messages' => [
            [
              'From' => [
                'Email' => "$fromm",
                'Name' => "$namee"
              ],
              'To' => [
                [
                  'Email' => "$to",
                  'Name' => ""
                ]
              ]
              'Subject' => "$subject",
              'TextPart' => "$text",
              'HTMLPart' => "$confirmationMail",
              'CustomID' => "AppGettingStartedTest"
            ]
          ]
        ];
        $response = $mj->post(Resources::$Email, ['body' => $body]);
        $response->success();
        $success=$response->getData()["Messages"][0]["Status"];

But if I want to add a Cc or Bcc, like :

 $body = [
      'Messages' => [
        [
          'From' => [
            'Email' => "$fromm",
            'Name' => "$namee"
          ],
          'To' => [
            [
              'Email' => "$to",
              'Name' => ""
            ]
          ],
          'Cc' => [
            [
                'Email' => "$cc",
                'Name' => ""
            ]
        ],
        'Bcc' => [
            [
                'Email' => "$cci",
                'Name' => ""
            ]
        ],
          'Subject' => "$subject",
          'TextPart' => "$text",
          'HTMLPart' => "$confirmationMail",
          'CustomID' => "AppGettingStartedTest"
        ]
      ]
    ];

then it does not work anymore. However the documentation seems to stipulate it's the right way : here

Any idea how to solve this ?

Many thanks.

Max
  • 51
  • 2
  • What do you mean with "does not work any more"? Did you enable PHP error reporting? Do you have any errors? Warnings? Have you tried an `echo()` on `$cc` and `$cci`, are the values OK? – fpierrat Jun 12 '20 at 13:37
  • This is from the page you provided, "Important: The recipients listed in `To` will receive a common message, showing every other recipient and carbon copy (CC) recipients. If you do not wish the recipients to see each other, you have to create multiple messages in the `Messages` array. " So, you may need to check the variables $cc, $cci for being a single recipient or multiple ones. – Mustafa Al Ameen Jun 12 '20 at 14:15
  • @MustafaAlAmeen Thanks. I know, what I want is to send ONE email, to one person as `To`, one as `Cc` and a last one as `Cci`, so I don't want to send multiple emails. – Max Jun 12 '20 at 15:06
  • @fpierrat Yes I did echo `$cc` and `$cci` and they are OK. – Max Jun 12 '20 at 15:08

1 Answers1

0

For properties To, Cc and Bcc, use comma separated recipients instead.

Optionally, in place of Recipients, you can use To, Cc and Bcc properties. To, Cc and Bcc can't be used in conjunction with Recipients. The properties can contain several recipients separated by comma using the following format john@example.com, <john@example.com> or "John Doe" <john@example.com>

Only Recipients accepts an array of recipients with name and email.

https://dev.mailjet.com/email/guides/send-api-V3/

flosej
  • 74
  • 4