PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old September 24th, 2002, 08:29 AM
Crowe Crowe is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: Huntsille, AL
Posts: 14 Crowe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to Crowe Send a message via AIM to Crowe
Mass mail with php

A while back I wrote a script to mass mail all the members on my writing site. I tested it on about 20 names to make sure it worked, and it does.

Now, I have a couple of practical questions about it. First here is what I do with the code, pseudo style.

select email from members;
while
send email to $email
$count++
echo $email $count
echo You just sent email to $count people

Now, I use @ to supress errors using mail. Some users didn't use valid email addresses in the old days ( I force that now ).

So, I have two questions..

1. If the email is not valid on a user will it cause the script to abort? Or since I use the @ will it continue to the next name.

2. I have less than a 1000 names. Would my script be able to send that many without running out of memory? Or should I select 100-200 at a time, use an offset and meta refresh?

This does not have to be an elegant solution. I only mass email the users 1 time per year as a reminder that we exist and of all the major changes in the last year.

Reply With Quote
  #2  
Old September 24th, 2002, 09:08 AM
crazytrain81 crazytrain81 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 232 crazytrain81 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
that's not a big deal

as far as the memory goes, you should be able to run it pretty easily.

when PHP suppresses an error, it just means that the error message is not displayed to the user. however, so long as the mail can leave your smtp server (which isn't dependant on a correct email address), you should be fine... if you get an error, it will be from some other physical server, and it won't be a PHP error because the mail couldn't be delivered.

Just a little advise, try something like this to build your mail:
PHP Code:
/*connect do db, then call this function. it will return true if the mail is sent, false if not, so..*/

if ($sendMail()) echo "mail sent";

function 
sendMail() {
$subject "";
$message "";
$toAddr "";
$sql SELECT DISTINCT email FROM members;
$result mysql_query($sql);
while (
$row mysql_fetch_row($result)) {
    
$toAddr .= "$row[0];";
   }
if (
mail($toAddr,$subject,$message)) return true;
else return 
false;


Reply With Quote
  #3  
Old September 24th, 2002, 07:49 PM
Ben Rowe
Guest
Dev Articles Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
yes, you can send your emails using the while statment, if one fails, it will move onto the next one, in regards to the 1000 names, it would probally put a big strain on your server and may even crash it, you might have to refresh the page after say 50 emails to stop if from happening

Reply With Quote
  #4  
Old March 19th, 2003, 04:30 AM
xf0rz xf0rz is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Posts: 1 xf0rz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Is it also possibel to use the CC: or BC: in the mail function?
Do you have to use the extraheader for this?

like:

from: URL, bc: address1; address2

?

Reply With Quote
  #5  
Old March 19th, 2003, 05:07 AM
jpenn jpenn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Washington, DC
Posts: 317 jpenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 3 sec
Reputation Power: 6
I would not recommend using the mail() function in PHP for anything over 100 mails, not even using it by breaking out your recipients in batches of 25, 50, 100 etc. and looping with the function. The mail function in general is pretty weak - your best option would be to open a socket to SMTP and package up the mail in an env and send it at once by using 'RCPT TO:' in the SMTP connection. Make your connection by using fsockopen() or popen(). Look through the user notes on fsockopen() and you will see a few examples of sending mail to SMTP using this...
__________________
~ Joe Penn

We work for free to help make this a valuable resource on the internet. Do you appreciate the help - did we provide help that will help you prosper and help that has contributed to sharpening your current skill set?

Show your appreciation and purchase something from our Amazon Wishlist's - it's simple and a great way to say thank you.




Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Mass mail with php


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT