2

I have a PHP function to email subscriptions to users. I use the BCC so the users cannot see each other, and everything works great, with one exception: I worry about having too many emails per line such that the header line is too long.

Note: I do break up the lists so that at most 75 emails addresses are used per email, but I don't want to go lower than that because of overhead.

I have tried several ways to fold or wrap the line, but no matter what I do, any addresses after the first fold are ignored. What is the proper way to do this?

I am interested in this for TO and CC fields as well.

steveo225
  • 11,394
  • 16
  • 62
  • 114
  • I bet most poeple here will tell you to use a class/framework instead of trying to do it yourself: PHP Mailer or PHP SwiftMailer – Shackrock Jan 22 '12 at 21:31
  • I have tried many combinations of commas, CRLF, tabs, spaces – steveo225 Jan 22 '12 at 21:31
  • @Shackrock: That teaches me nothing, plus then I have to find, integrate, test somebody else's framework, when mine already works (which it does, I am just trying to fold lines properly to avoid potential future problems) – steveo225 Jan 22 '12 at 21:34
  • 1
    @steveo225 Teaches you? I'm saying, these frameworks are made to send email, and lots of it. By using those frameworks instead of trying to BCC 75 people with the mail() function, you can send everyone an individual email - properly, and looking LESS like spam to email clients. Just my 2 cents... take it or leave it. – Shackrock Jan 22 '12 at 21:38
  • 3
    @Shackrock: I understand. But my system is already setup, already doesn't generate email that looks like spam, is fast and useable, with just one issue that I'd like to fix. FYI: somebody has to code up frameworks, if we all rely on others, nothing new or better will ever be created. And I never said I was using the `mail` function. – steveo225 Jan 22 '12 at 21:46

1 Answers1

2

I strongly suggest you use a ready-made email library or framework (I have experience with Zend_Mail which you can use without the rest of ZF). In any case when you fold email header lines you need to ensure that all lines after the 1st line begin with at least one space character, like so:

Bcc: foo1@example.com, foo2@example.com, ...
  foo3@example.com, ...

Make sure you use CRLF for line breaks and not just LF ("\r\n" rather than "\n").

See https://www.rfc-editor.org/rfc/rfc2822#section-2.2.3 for more info.

Community
  • 1
  • 1
shevron
  • 3,463
  • 2
  • 23
  • 35
  • Yeah, I found that document. Doesn't seem to work as expected. Perhaps there is an issue with the version of `sendmail` I am using. – steveo225 Jan 23 '12 at 00:20