spoco Posted December 4, 2008 Share Posted December 4, 2008 Hello. I have a working script that is pulling e-mails from a MySQL database and sending a coinfirmation. I would like to add an email address that would be sent for all classes. (e.g. copy the instructor on all classes) Is there a way to do this by simply adding a line in the script, or do I need to call the instructor email from MySQL? <?php require_once("../databaseconn.php"); $subject = $_POST['subject']; $body = $_POST['body']; $class_id = $_POST['id']; $email = ""; mysql_select_db('training', $databaseconn); // get email of students in class $emailsSQL = sprintf("select email from students where class = %s and status='approved'",$class_id); //echo $emailsSQL; $emailsResult = mysql_query($emailsSQL, $databaseconn) or die(mysql_error()); $count = mysql_num_rows($emailsResult); $i=0; while($row_emails=mysql_fetch_row($emailsResult)){ $i++; $email .= $row_emails[0]; if ($i<$count) $email .=","; } $query_message = sprintf("SELECT * FROM messages WHERE id=3"); $message = mysql_query($query_message, $databaseconn) or die(mysql_error()); $row_message = mysql_fetch_assoc($message); $query_class = sprintf("SELECT * FROM classes WHERE id=".$class_id); $class = mysql_query($query_class, $databaseconn) or die(mysql_error()); $row_class = mysql_fetch_assoc($class); // set email headers $headers = "From: ".trim($row_message['fromemail']). "\r\n"; /* // set email body $body .= "\n\nClass: " . $row_class['name']; $body .= "\nDates: " . $row_class['daterange']; $body .= "\nTime: " . $row_class['times']; */ // send email to students $was_sent = mail ($email,$subject,$body,$headers); // redirect header(sprintf("Location: %s", $doc_root."admin/classes.php")); ?> Link to comment https://forums.phpfreaks.com/topic/135562-e-mail-using-a-php-script/ Share on other sites More sharing options...
Mchl Posted December 4, 2008 Share Posted December 4, 2008 Change this while($row_emails=mysql_fetch_row($emailsResult)){ $i++; $email .= $row_emails[0]; if ($i<$count) $email .=","; } to while($row_emails=mysql_fetch_row($emailsResult)){ $email .= $row_emails[0] . ","; } $email .= "[email protected]"; //or insert here variable with desired email Link to comment https://forums.phpfreaks.com/topic/135562-e-mail-using-a-php-script/#findComment-706220 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.