Page 1 of 1

How to add Bcc in mail

Posted: 2019-04-28 15:54
by RonP
Hi,

I like to put a Bcc into a mail function. I haven’t find an example for this yet.
How can I make this work?

Thanks in advance

Ron

Re: How to add Bcc in mail

Posted: 2019-05-08 06:57
by RonP
Hi There,
Someone a hint for me?

Re: How to add Bcc in mail

Posted: 2019-05-08 07:48
by jsetzer
Hi,

AppGini's sendMail-function in incFunction.php does not support CC or BCC, yet (Ver. 5.75), allthough the PHPMailer class being used, does. I have asked Ahmed to support CC and BCC. I think it's on his roadmap.

In between I have solved it this way:
  1. Copy the sendMail-function from incFunction.php
  2. Paste it in one of your PHP files and give it a different name (important!), for example sendMailEx
  3. Check the PHPMailer documentation here:
    https://github.com/PHPMailer/PHPMailer
  4. Change the new sendMailEx-function:
    below...

    Code: Select all

    $pm->addAddress($mail['to'], $mail['name']);
    
    ...add something like...

    Code: Select all

    if ($mail['bcc]) $pm->addBCC($mail['bcc']);
    if ($mail['cc']) $pm->addCC($mail['cc']);
    
  5. In your calling function, add the BCC recipient to your $mail-array like this:

    Code: Select all

    $mail['bcc'] = "[email protected]";
    
  6. Now you can call the new sendMailEx-function:

    Code: Select all

    sendMailEx($mail);
    
That should do the trick for now. Hope this helps!

Best,
Jan

PS: If you need more than one bcc- or cc-recipient, you can for example add a comma-separated list like this... ...and in your sendMailEx-function, split the string using PHP explode-function (https://www.php.net/manual/de/function.explode.php) and add each address using $pm->addCC($item);

Re: How to add Bcc in mail

Posted: 2019-05-09 07:08
by RonP
Hi Jan,
Thanks for the answers. As I"m not that familiar with PHP, I"ll give it a try.
I"m off the street now for a while :D
Ron