hello, I have a list of emails in a .txt file and I want to send a newsletter using it. I am not really good in php, I knwo there is mail() function that can do this, but I don't know how to read from the .txt file and send an email for every line...
How is this list of emails separated? Is there a line break between each one? E.g. Email1 Email2 Email3 Email4 etc... Code (markup): or how? If they are separated by line breaks, try this: <?php /** * Simple Mailing List Script by Dennis M. * (C) 2009, Dennis M. All Rights Reserved. * */ // Config parameters $emailfile = "emails.txt"; $msgfile = "message.txt"; $subject = "Message Subject"; $header = "From: Your Name <you@yourdomain.com>\r\n"; // Grab emails and explode $emails = file_get_contents($emailfile); $emails = explode("\n",$emails); // Now let's send an e-mail to each user foreach($emails as $key => $address){ mail($address,$subject,file_get_contents($msgfile),$header); print "Message sent to ".$address."<br />\n"; } ?> PHP: Regards, Dennis M.
Depending on the service/host he uses, and the amount of mails to be sent, this might be a horribly bad idea - to send an email separately to each recipient. Better to just send the email to his own email address, and add all the email-addresses in the BCC-field. That way everyone gets a copy, and there is way less stress on the email-server.
Yeah I thought about that later. Just a simple way of doing that: <?php /** * Simple Mailing List Script by Dennis M. * (C) 2009, Dennis M. All Rights Reserved. * */ // Config parameters $emailfile = "emails.txt"; $msgfile = "message.txt"; $subject = "Message Subject"; $address = "your@email.address"; // Grab emails and explode $emails = file_get_contents($emailfile); $emails = str_replace("\n",",",$emails); $header = "From: Your Name <".$address.">\r\n BCC: ".$emails."\r\n"; // Now let's send an e-mail to each user and a copy to yourself mail($address,$subject,file_get_contents($msgfile),$header); print "Message sent to ".$address.",".$emails."<br />\n"; ?> PHP: Regards, Dennis M.
Uhm. The receiving mailserver does not see the BCC recipients. So... how this would affect either Yahoo or Gmail is beyond me?
2500 emails all 99% identical subject/body (only recipient different) all hitting the server at once from same IP/server/sender you think they can't figure that out? it will eventually be considered spam
Perhaps having a setting for the time (in seconds) between the emails sent will help solve that issue?
its called "throttling" and it definitely helps along with customization of the emails subject and body
well, in order for this to go through and not be marked as spam, you need to make each and everyone unique, otherwise, theres no chance of it going through, and you will have yourself a blacklisted ip
Uhm - again, BusinessCoach - you're assuming that all the emails goes to the same receiving emailserver? Of course that might be considered spam, but... seriously. It will probably be diversified between companies, Gmail, Yahoo mail (they use several different server, no link between them), Hotmail, private servers/email... of course one should use some sort of throttling, and one can easily add for instance each receivers name to the subject to make it more unique, but... 2500 mails from a single server isn't really all that weird. It's probably better to ask the question: does the host the OP is sending from allow to send out bulk mail with more than say, 500 recipients? That's probably a bigger problem.
no assumption, I pretty much said what I meant. I don't know what he is sending, to how many or from what kind of machine. naturally its best to be on a dedicated server as shared hosting has many restrictions, including hourly/daily caps. However, irrespective, too many -- even as few as 100 going to the same domain (gmail, hotmail, yahoo, etc) can get you blocked...in addition carriers like AT&T who have backbones and provide email, will block you also. I guess you have to be someone who sends emails a lot to even know this stuff...
I've worked for a couple of ISPs in technical support departments, so I have fairly good knowledge of both the receiving and sending portion of the email-service provided. I don't recide in the US, of course, and there might be some stricter limitations, but as far as I know, here in Norway, were there isn't much of bandwidth caps, or anything similar, most email-server configurations in-house, at least, deals with everything from hundred of thousands to millions of emails each day - of that, roughly 65-75% is considered spam. A single mail sent to say... 100, 200, 300 recepients on the same receiving server might very well be considered spam - although, examination of the content will normally reveal whether it's to be considered spam, thereby increasing the level of caution for that sender, or not. Depending on what is being sent, the milage may vary, of course. Again - a receiving email-server does NOT see the BCC-fields - it sees that there is a mail for one of its receipients, and turns the mail to that inbox. Heuristics and similarities might make another 50 of the same subject email received within a short period of time considered as spam, but again - it might not happen. If we're talking thousands of email going out, the OP should consider not only talking to his hosting service, but also to several white-list companies, to get his name on lists so as to avoid false marking as spam. All that said, all this is assuming the script is for actual legitim use, of course.
definitely a big difference between norway and north america. i doubt u guys are targeted towards spam as much if necessary i can point you to the TOS links from the providers themselves...but I am sure thats pointless....some people "know" everything without knowing anything you don't need fancy "heuristic algorithms" to realize that the exact same subject, exact same body content, sent at the exact same time, from the exact same address, hitting your server at the exact same time for multiple users....is a mass message.
You still need to have an actual check of the content of the email. If you don't, then the email-provider is rubbish. Which, of course, it is, if you are using Yahoo or something similar. There is probably more of both bandwidth caps and spam problems in the US - I have no doubt about that. Therefore it is wise to approach providers before you start up doing email-listings and such. But again - if a mailserver croaks and deems something spam just because it receives about 100 identical messages, the setup of the mailserver should be put to scrutiny, not the message - of course the message might be spam (most likely is, even), but that doesn't mean there isn't lots of legitimate reasons for sending out a "mass email" to a hundred or more recepients. For instance, I'm an admin for a local organisation - one of the uses of the member-database is of course to send out "mass email" regarding events and happenings, asking them to remember to register for such events etc. Not too big an organisation, so the amount sent out varies from maybe 150 - 500 depending on which groups need to be told. We don't really send out that often, but we did contact our host to check with them first, if there was a problem sending out such amounts - the only thing they didn't want ut to do was make it send single emails - use the CC or BCC fields, was basically what we were told. Which, of course, makes perfect sense. Spam is a problem, but mostly it is a nuisence, and nothing more. The bandwidth costs is the main problem, and as I've said, I'm guessing they can be both steeper and more of a problem in the US.
again...you have to be someone who actually sends mail out fequently and have dealt with it....otherwise your just quoting something you read or theorized in your mind and never experienced.