Guys I have created a small script that picks 100 email addresses from database and send emails one by one. I have set timer of 5 seconds to wait between each email sending. Whenever an email is send script does the following 1. Display email address, "delivered" on table row 2. Updates delivery time in database 3. Wait for 5 seconds for next email Script is working fine i.e. sending emails and updating delivery time in database. But script don't display "Delivered" immediately after mail is sent. Script went on wait and process every thing in background. For example last time script only printed 4 records and then went on sleep (did not print further email addresses) but sent all emails. I checked this from delivery time from database. What problem it might be, how can I force script to print required things immediately. It looks there is some thing that I don't know about "printing". I am using print and wait commands for this. GCS
I assume you're tracking (looking at) the mail sending progress in real time at your browser, and I assume you're code is pure PHP with some HTML... If it's that so, I think you have to combine Javascript with your code (maybe AJAX?) to see the changes immediately. PHP is server side and all the changes (i.e. message "Delivered") that are happening 'right now' will be seen AFTER reloading the page. I'm sure this issue can be solved with JS/AJAX...
You understood right. I want to see email sending progress in real time. Right now script prints results of first 5-10 emails then stop printing but keep working and send all emails. My script is as follows: if(mail($line, $emailsubject1, $emailbody, "$email_headers")) { print 'Delivered'; $q_det = "update address set last_sent=now() where email='$email'"; db_exec($q_det); } else { print 'Problem'; } How I can change this script so script print results real time? GCS
Is there a while (or other) loop that executes this code : if(mail($line[email], $emailsubject1, $emailbody, "$email_headers")) { print 'Delivered'; $q_det = "update address set last_sent=now() where email='$email'"; db_exec($q_det); } else { print 'Problem'; } Code (markup): ???
plus make sure that u will use some pro smtp server or pro mail server other than mail() function on web hosting otherwise this way your emails will start to go to bulk/junk folder after some days.
I think you should investigate your part of script controlling the 5 second delay between the mail() function. If the script is really DOING the job (sends out those emails and updates the database), I'd look for the error there... Why don't just select all the rows from the database with the recipients, send the email and print a message i.e. : $query = "SELECT * FROM recipients WHERE confirmed = '1' ORDER by id ASC"; $result = mysql_query($query) or die('Error : ' . mysql_error()); while($row = mysql_fetch_array($result)) { $recipient = $row['recipient_email']; if (mail($recipient, $emailsubject1, $emailbody, $email_headers)) { echo('<p>Message delivery succeeded.</p>'); echo('<p>Recipients of the Newsletter :</p>'); print ($recipient); } } Code (markup):
I agree with gaven, consider to implement Swift Mailer for sending those emails! You can send emails using SMTP, sendmail, postfix or a custom Transport implementation of your own with this free library!
I am totally new to sendmail and postfix! Do I need to make much changes to my existing script to send emails through this system? Will my mails be delivered 100% into Inbox if I use these methods? GCS
Someone recommended me to use set_time_limit() to increase max_execution_time limit. I calculated estimated time of script that was around 1 hour i.e. 3600 seconds. 200 emails during one hour and 18 seconds wait between each. So I set max_execution_time to 3600 and now every thing is working fine. GCS