Ashmit Posted January 25, 2012 Share Posted January 25, 2012 Hello, I am new in PHP and I want a script for sending multiple emails using the php and i am calling that email address from database.I also want to change the status field from database from No to Yes once I send the particular emails. How to do that? I need a urgent help Following is my code for calling the email address <? mysql_connect("localhost","root","123") or die(mysql_error()); // my database connection mysql_select_db("localacct") or die(mysql_error()); $sql = "SELECT email FROM company where status='No'"; $res = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_assoc($res) ) { $area .= $row['email']. ", "; } // read the list of emails from the file. $email_list = explode(',', $area); // count how many emails there are. $total_emails = count($email_list); // go through the list and trim off the newline character. for ($counter=0; $counter<$total_emails; $counter++) { $email_list[$counter] = trim($email_list[$counter]); } $to = $email_list; //echo $to; $t0 = ""; $subject = "Test email"; $message = wordwrap($message, 100); $from = "my email address"; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= "From: $from"; mail($to,$subject,$message,$headers); if ($count % 10 == 0) { sleep(5); // this will wait 5 secs every 10 emails sent, and then continue the while loop } $count++; } ?> Many Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/255742-how-to-use-php-to-send-multiple-emails-at-a-time/ Share on other sites More sharing options...
trq Posted January 25, 2012 Share Posted January 25, 2012 You forgot to tell us what your problem is. Oh, and to use tags when posting code. Quote Link to comment https://forums.phpfreaks.com/topic/255742-how-to-use-php-to-send-multiple-emails-at-a-time/#findComment-1310976 Share on other sites More sharing options...
Ashmit Posted January 25, 2012 Author Share Posted January 25, 2012 Sorry, My problem is that code is not working. If you could help me then it will be great. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/255742-how-to-use-php-to-send-multiple-emails-at-a-time/#findComment-1310982 Share on other sites More sharing options...
Ashmit Posted January 25, 2012 Author Share Posted January 25, 2012 Somebody Pleas Help Me :'( Quote Link to comment https://forums.phpfreaks.com/topic/255742-how-to-use-php-to-send-multiple-emails-at-a-time/#findComment-1310994 Share on other sites More sharing options...
dzelenika Posted January 25, 2012 Share Posted January 25, 2012 why are you waiting 5 seconds? Is your script throwing some error or doing something else? Quote Link to comment https://forums.phpfreaks.com/topic/255742-how-to-use-php-to-send-multiple-emails-at-a-time/#findComment-1310999 Share on other sites More sharing options...
Ashmit Posted January 25, 2012 Author Share Posted January 25, 2012 Because Initially I was getting some timeout error. so I did this Quote Link to comment https://forums.phpfreaks.com/topic/255742-how-to-use-php-to-send-multiple-emails-at-a-time/#findComment-1311000 Share on other sites More sharing options...
dzelenika Posted January 25, 2012 Share Posted January 25, 2012 you should put email command into for loop! Quote Link to comment https://forums.phpfreaks.com/topic/255742-how-to-use-php-to-send-multiple-emails-at-a-time/#findComment-1311005 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.