RE: [PHP] Mass Mailing Using PHP

From: Date: Mon, 27 Sep 2004 12:53:03 +0000
Subject: RE: [PHP] Mass Mailing Using PHP
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-197947@lists.php.net to get a copy of this message
Out of curiousity, is there a limit to the number of email addresses you can include in the BCC field? Much warmth, Murray -----Original Message----- From: Jim Grill [mailto:jgrill@web-1hosting.net] Sent: Monday, 27 September 2004 10:43 PM To: Graham Cossey; php-general@lists.php.net Subject: Re: [PHP] Mass Mailing Using PHP > Are your users' details in a database? > > If so simply read through the database mailing to each user, something like: > > <?php > $message = "Hello everyone"; > $subject = "Hello"; > $headers = "From: Someone <someone@somewhere.com>\r\n"; > $sql = "SELECT user_name, email FROM user"; > $result = mysql_query($sql) or die ("Query failed: " . mysql_error()); > while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) > { > $email = $row['email']; > mail($email, $subject, $message, $headers); > } > ?> > If the message is the same for each user then use the Bcc header and save yourself some overhead. There is no need to send a new mail to each recipient in a loop. If your on a shared system I'm sure your ISP will appreciate not getting bombed by your script. ;-) loose example: while ($row = mysql_fetch_assoc($result)) { $bccList .= "<{$row['email']}>,"; } /*remove the last comma*/ $bccList = substr($bccList,0,-1); $headers .= "Bcc: $bccList\n"; /*mail only one time*/ mail($email, $subject, $message, $headers); Jim Grill -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.general (#197947) next »