vozzek Posted March 6, 2008 Share Posted March 6, 2008 Hi all, Quick problem: I'm trying to read the email addresses from my mailing list, which is a .txt file separated by line breaks. I need to append this into the "Bcc: " section of the $headers variable so when I send the email everyone is blind to everyone else. I'm using fgets, and it doesn't seem to be picking up the line breaks. When I append new addresses to the file I used "/r" as the line terminator instead of "/n", but from what I've read that shouldn't really matter. Here's my code: $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= 'From: customerservice@thefrogandtheprincess.com' . "\r\n"; $myFile = "test_list_TFATP.txt"; $fh = fopen($myFile, 'r'); while(!feof($fh)) { $email_address = fgets($fh, 4096); $headers .= 'Bcc: '.$email_address."\r\n"; } fclose($fh); mail($to, $subject, $message, $headers); Right now I'm using a three email test file. The customerservice email gets through okay, but at the very top of the body of the email I see the following line: Bcc: email1@whatever.com Bcc: email2@whatever.com Bcc: email3@whatever.com Bcc: So the three magical questions are: 1) Why isn't the $headers variable being broken up line by line so each email can be sent? 2) Why is this showing up in the body of the email? 3) What's with the extra "Bcc: " at the end of the read? Wouldn't the eof marker prevent that, or should I check for a null $email_address value before appending to $headers? Thanks in advance for the help. Quote Link to comment Share on other sites More sharing options...
vozzek Posted March 6, 2008 Author Share Posted March 6, 2008 Okay, I cheated (commence bashing me). Instead of reading the file line-by-line, I did the following: $headers .= 'Bcc: '; $mailstr = file_get_contents("test_list_TFATP.txt"); $mailstr = eregi_replace("\n",",",$mailstr); // Replaced page breaks with commas $headers .= $mailstr.'customersupport@thefrogandtheprincess.com' . "\r\n"; Does anyone see a problem with this? What's the character/size limitations on <b>file_get_contents</b> anyway? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.