sstangle73 Posted June 14, 2011 Share Posted June 14, 2011 Hey, I have a system set up where it selects from a database and sends an email to everyone. But the problem I am having is that it sends every email twice. I am not quite sure why it does that. Also, it takes the page FOREVER to load. Could someone help me to fix/optimize this code? Thanks! edit: Sometimes the browser comes back with this instead of a success message: No data received Unable to load the webpage because the server sent no data. Here are some suggestions: · Reload this web page later. Error 324 (net::ERR_EMPTY_RESPONSE): The server closed the connection without sending any data. $query="SELECT * FROM `" . $table . "` WHERE status LIKE 'Accepted%'"; $result=mysql_query($query); while($array=mysql_fetch_assoc($result)){ $coach_email = $array['coach_email']; $contact_email = $array['contact_email']; $to = $coach_email . ", " . $contact_email; $subject = $_POST["subject"]; $message = $_POST["message"]; $message = stripslashes($message); $from = "Mad Dog Mania Showcase Tournament <[email protected]>"; $reply = "[email protected]"; $headers = 'From: ' . $from . "\r\n"; $headers .= 'Reply-to: ' . $reply . "\r\n"; $headers .= 'BCC: [email protected]' . "\r\n"; $headers .= 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; mail($to,$subject,$message,$headers); } $success=true; Link to comment https://forums.phpfreaks.com/topic/239300-php-mail/ Share on other sites More sharing options...
gizmola Posted June 14, 2011 Share Posted June 14, 2011 This is the type of problem best run from CLI where you don't have the same type of concerns in regards to timeouts and things of that nature. Link to comment https://forums.phpfreaks.com/topic/239300-php-mail/#findComment-1229396 Share on other sites More sharing options...
sstangle73 Posted June 14, 2011 Author Share Posted June 14, 2011 I am confused what that means? Link to comment https://forums.phpfreaks.com/topic/239300-php-mail/#findComment-1229690 Share on other sites More sharing options...
gizmola Posted June 14, 2011 Share Posted June 14, 2011 Run your script from the command line: php -f myscript.php Typically a script like that would be setup on some schedule. On a linux host you would do this with cron. Link to comment https://forums.phpfreaks.com/topic/239300-php-mail/#findComment-1229692 Share on other sites More sharing options...
sstangle73 Posted June 14, 2011 Author Share Posted June 14, 2011 I need the script to be accessible by non tech savy people (plus 1 and 1 does give me command line access anyway) Is there a way to make that possible? Link to comment https://forums.phpfreaks.com/topic/239300-php-mail/#findComment-1229695 Share on other sites More sharing options...
gizmola Posted June 14, 2011 Share Posted June 14, 2011 You can call an operating system program using exec(). So you could make a simple script that runs the script using exec and displays a message stating that it was run. Something like this: exec('/usr/bin/php -f /path/to/script/yourscript.php &'); Link to comment https://forums.phpfreaks.com/topic/239300-php-mail/#findComment-1229700 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.