1

I'm trying to send same email to several users at once. They should not see each other's email addresses, so I add them as Bcc in the header.

However, the problem is that Drupal seems to require the $to parameter passed to drupal_mail() function. I tried passing both NULL and an empty string but without success. System would return the Unable to send e-mail. message.

I don't want to use some random email address instead and I want to avoid new modules.

How can I send an email just with BCC recipients?

  • 2
    You can't - emails require at least one recipient, that's not a Drupal thing. Just send it to variable_get('site_mail'), that's the most oft-used solution I've seen – Clive Nov 29 '13 at 14:53
  • 1
    Could also loop through your list of addresses and send them one by one. – Beebee Nov 29 '13 at 14:59
  • Thanks for quick response Clive. I guess I'll have to send them through as queue batch and see how other modules solved this problem. Please add your comment as a separate answer so I can accept it. – Aram Boyajyan Nov 29 '13 at 15:00
  • The way I did it was: ask admins to configure "resend" address on the mail server. Update recipient list daily via XML. Yes, hard part was on their side. Then I was just sending mail to that address and mailserver was re-sending it where needed. So it's like @Beebee solution, only with "loop" moved elsewhere ;) – Mołot Nov 29 '13 at 15:03
  • 1
    @Ivanhoe123 I know. Kinda. I know that only way to really know is to test. It depends on your server's performance. And performance of it's network. And exact configuration. And the fact if you are using mailserver or sending directly. If via mailserver, then it depends on it's performance too. If directly, performance of recipient's servers may be (or not) a problem. Too many factors to really know. But with good use of batch api you should be reasonably safe. – Mołot Nov 29 '13 at 15:09
2

You do this by putting the string 'undisclosed-recipients:;' (notice the colon and semicolon at the end) is the $to parameter you pass to the drupal_mail function. E.g.:

drupal_mail('mymodule', 'send', 'undisclosed-recipients:;', $language, $params);

You can now add the list of bcc-recipients to the header.

  • Didn't know for this approach, thanks a lot! Do you know if it will generate some error logs in the background or this is an accepted way of leaving recipient empty? – Aram Boyajyan Dec 16 '13 at 16:29
  • 1
    This is the accepted way of leaving the recipient empty. It is used in examples in RFC 2822. – Free Radical Dec 16 '13 at 16:32
  • Thanks again for lightning fast response :) I will check this and post back/mark the question as the answer. – Aram Boyajyan Dec 16 '13 at 16:33
  • Thanks once again, and sorry it took me so long - I simply forgot about it. This worked perfectly. – Aram Boyajyan Nov 25 '15 at 21:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.