jmr3460 Posted September 16, 2009 Share Posted September 16, 2009 Hello all, It has been a little while that I could not find a solution to my small problem. I have made a calendar that I have only been linking to a php page with a while loop that loops through all entries on this calendar. I am trying to send this while loop in the email instead. I am able to send the email as html email but the only thing sent in the email is the last loop. My question is "How do I do a while loop in my email? I have set this script up to be run with CRON Job and some of my lines are commented out so I can get it going. <?php ini_set ("display_errors", "1"); error_reporting(E_ALL); //This code gets the timeso CRON knows what to do $host = "localhost"; $user = "username"; $pass = "password"; $table = "mailer"; $database = "arscnaor_mailer"; //sets date in seconds to be inserted into Db till next cron job runs $date = time(); mysql_connect($host, $user, $pass); mysql_select_db($database) or die(mysql_error()); //I want to find the last entry of time in my $table $sql = mysql_query("SELECT time FROM $table ORDER BY id DESC LIMIT 1;"); $info = mysql_fetch_array($sql); //creates a new variable to compare with last time entry of $table //(+ 60 will be changed to equal 1 week once the script is working) $result = ($info['time'] + 604800); $newdate = time(); //I am trying to compair my two times and if $newdate //if ($newdate < $result){ // exit(); //}else{ //This code opens the calendar for events to be mailed $calendar_db = "arscnaor_calendar"; $calendar_table = "calendar"; mysql_connect("localhost", "$user", "$password")or die("cannot connect to server"); mysql_select_db("$calendar_db")or die("cannot select DB"); $calendar_sql = "SELECT * FROM calendar"; $calendar_result = mysql_query($calendar_sql) or die(mysql_error()); while ($calendar_data = mysql_fetch_array($calendar_result)){ $groupname = $calendar_data['groupname']; $event_title = $calendar_data['event_title']; $location = $calendar_data['location']; $address = $calendar_data['address']; $city = $calendar_data['city']; $state = $calendar_data['state']; $event_date = $calendar_data['date']; $calendar = "<li><b>$groupname</b> is sponsoring:<br /> $event_title is at $location.<br /> $address<br /> $city, $state</li>"; echo $calendar; } //This code gets me into my emails for BCC's $email_db = "arscnaor_users"; $email_table = "registered_users"; mysql_connect("localhost", "$user", "$password")or die("cannot connect to server"); mysql_select_db("$email_db")or die("cannot select DB"); $email_sql = "SELECT * FROM $email_table"; $email_result = mysql_query($email_sql) or die(mysql_error()); while ($email_data = mysql_fetch_array($email_result)){ $email = $email_data['email']; } $to = "[email protected]"; $subject = "Upcoming Arkansas Regional Events"; $headers = "FROM: [email protected]"; $headers .= 'MIME-Version: 1.0' . "\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\n"; //$headers .= 'BCC: '$email' "\n"; $upcoming = "<html><body><h1>Upcoming Events for the Arkansas Regional Calendar</h1> <p style=\"text-align:center;\">You can find more information at <a href=\"http://www.arscna.org/activities\">Activities</a><br /> The following is only a list of the events that have been added to the Arkansas Regional Calendar. <br /> If you are aware of an event that is not on this list please click the activities link above and add any NA event to our calendar.<br /> Please let other addicts know that they can be put on this email list by registering their email address at the <br /> following link <a href=\"http://www.arscna.org/service/mailingList/\">Mailing List</a>. </p> <ul>$calendar</ul> <p>If you wish to be removed from this list you may click this link <a href=\"http://www.arscna.org/service/mailingList/\">Unsubscribe</a> and update<br /> your profile to be unsubscribed.<br /> Thank You for leting us serve you.<br /> Website Subcommittee</p>"; mail($to,$subject,$upcoming,$headers); //This is inserted in the date table so CRON won't run script too early //I am also depending on search engines as well because they will open the script as well //the time table stops this from happening //mysql_query("INSERT INTO $table (id, date)VALUES('','$date')") or die(mysql_error()); //} ?> Right now it is a little unorganized and I don't have much commented. I usually have been tiding things up after I have it working good. Quote Link to comment https://forums.phpfreaks.com/topic/174419-solved-php-while-loop-in-my-php-email/ Share on other sites More sharing options...
jmr3460 Posted September 16, 2009 Author Share Posted September 16, 2009 I guess I was not as clear as I should be. Everything in this script works except my while loop in the email. I have tried to create a variable with this information in it. Do I need to make it am array somehow? Thanks for any help. jmr3460 Quote Link to comment https://forums.phpfreaks.com/topic/174419-solved-php-while-loop-in-my-php-email/#findComment-919804 Share on other sites More sharing options...
backie Posted September 17, 2009 Share Posted September 17, 2009 Umm while loop in the email? Only while loop I seen near the email was just before it where it was getting email address that weren't gussing used. while ($email_data = mysql_fetch_array($email_result)){ $to = $email_data['email']; $subject = "Upcoming Arkansas Regional Events"; $headers = "FROM: [email protected]"; $headers .= 'MIME-Version: 1.0' . "\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\n"; //$headers .= 'BCC: '$email' "\n"; $upcoming = "<html><body><h1>Upcoming Events for the Arkansas Regional Calendar</h1> <p style=\"text-align:center;\">You can find more information at <a href=\"http://www.arscna.org/activities\">Activities</a><br /> The following is only a list of the events that have been added to the Arkansas Regional Calendar. <br /> If you are aware of an event that is not on this list please click the activities link above and add any NA event to our calendar.<br /> Please let other addicts know that they can be put on this email list by registering their email address at the <br /> following link <a href=\"http://www.arscna.org/service/mailingList/\">Mailing List</a>. </p> <ul>$calendar</ul> <p>If you wish to be removed from this list you may click this link <a href=\"http://www.arscna.org/service/mailingList/\">Unsubscribe</a> and update<br /> your profile to be unsubscribed.<br /> Thank You for leting us serve you.<br /> Website Subcommittee</p>"; mail($to,$subject,$upcoming,$headers); } may be what your wanting. Quote Link to comment https://forums.phpfreaks.com/topic/174419-solved-php-while-loop-in-my-php-email/#findComment-919833 Share on other sites More sharing options...
jmr3460 Posted September 17, 2009 Author Share Posted September 17, 2009 I found it. I found the function: $message .= file_get_contents("http://www.path/to/file"); I wrote a file that runs a while loop from my calendar database. I am not sure that It is getting all of the data but it is a start. I found out how to run a while loop inside an email. Quote Link to comment https://forums.phpfreaks.com/topic/174419-solved-php-while-loop-in-my-php-email/#findComment-919867 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.