E-mail with replyTo does not work

i used this code example: Mails optional with BCC - #2 by texnixe

I have the problem that the replyTo option does not work. However, when I use the cc option, everything is OK.

my if query is as follows:

// $data['email_cc'] is a Checkbox

if (($data['email_cc'] == 'on') && !empty($data['email'])) {
  //$email['replyTo'] = esc($data['email']);
  //$email['replyToName'] = esc($data['name']);
    $email['cc'] = esc($data['email']);
}

cc is something else than replyTo!

That’s what I thought, otherwise the options wouldn’t be available. However, how can I send a copy of the request to the user if he has activated the checkbox?

I have set the option “to” in config.php. Will this be overwritten if I use the “to” option?

'to' => [
    'jane@doe.com', // is already present in config.php, I would leave this line empty
    'mark@otto.com'
],

Well, yes, use the cc option to send a copy to the user, unless you want the user to be the recipient. But that doesn’t seem to be the case.

But it would be the case that the user should not see that he is in the CC and gets to see the other e-mail address.

I don’t understand what you want to achieve. You are asking how you can send a copy of the request to the user. The answer to this is use the cc option.

// That's how it should work?

$email['to'] = [
   ['abc@tld.de', 'FullName'], // Does this line have to be submitted as well? Or is the additional recipient sufficient to use the first recipient from config.php?
   [esc($data['email']), esc($data['name'])]
];

Okay then, maybe my wording was wrong. The request should always be sent to a specified recipient that is stored in config.php. If the user wants to have a “copy” for himself, he can activate a checkbox for this. So that the user receives the same e-mail but without seeing another e-mail address.

Yes, because your to option` overwrites the option set in the config, unless you merge config options and new option.

In that case you shouldn’t have multiple to addresses, as they will be visible to all recipients.

Then send to the user as recipient (to), and put the other recipient(s), who you don’t want to disclose to the user in bcc.

1 Like

How can I understand that, do you have an example for me?

You can use array_merge to merge the to array from your config with the recipients array in your controller.

But see what I wrote in my last reply.

BCC is the solution