jarv Posted August 5, 2011 Share Posted August 5, 2011 hi, I wrote an email script but it doesn't work properly?! the intention is, in the dropdown ID has a value of either '999999', '1' or '2' at the moment as there are 2 IDs in the database if the ID = 999999 then send email to ALL - ie; 1 and 2 else get ID and post to that ID form: <form action="send-massemail-script.php" method="post"> <fieldset> <!-- Set class to "column-left" or "column-right" on fieldsets to divide the form into columns --> <p> <label>Selected Bookings</label> <select name="id"> <option value="999999">Send to all customers</option> <?php while($row1 = mysql_fetch_array($result3)) { echo '<option value="'.$row1['id'].'">'.$row1['customer_name'].'</option>'; } ?> </select> </p> <p> <label>Email Title</label> <input class="text-input small-input" type="text" id="small-input" name="EmailTitle" /> </p> <p> <label>Email Body</label> <textarea rows="15" cols="79" name="EmailBody" id="textarea" class="text-input textarea wysiwyg" style="width: 930px; height: 247px;"></textarea> </p> <p> <input class="button" type="submit" value="Send Email" /> </p> </fieldset> <div class="clear"></div><!-- End .clear --> </form> script: <?php error_reporting(E_ALL); print_r($_POST); include_once("config.php"); $EmailTitle = mysql_real_escape_string($_POST['EmailTitle']); $EmailBody = mysql_real_escape_string($_POST['EmailBody']); $id = mysql_real_escape_string($_POST['id']); echo $id; if($id == '999999'){ $query5 = "SELECT * FROM aarbookts_booking_bookings"; $result5 = mysql_query($query5); while($row5 = mysql_fetch_array($result5)) { $customer_name = $row5['customer_name']; $EmailBody = filter_input(INPUT_POST, 'EmailBody', FILTER_SANITIZE_STRING); $to = $row5['customer_email']; $from_header = "From: [email protected]\r\n"; $from_header .= "Reply-To: ". strip_tags($to) . "\r\n"; $from_header .= "MIME-Version: 1.0\r\n"; $from_header .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; $EmailBody1 = '<html><body>'; $EmailBody1 .= '<p><strong>Dear '.$customer_name.'</strong></p>'; $EmailBody1 .= '<p>'.$EmailBody.'</p>'; $EmailBody1 .= '</body></html>'; $EmailTitle = 'Subject'; if($EmailBody != "") { //send mail - $subject & $contents come from surfer input mail($to, $EmailTitle, $EmailBody1, $from_header); // redirect back to url visitor came from $msg = "Mass email sent"; // header("Location: send-mass-email.php?msg=$msg"); } else { print("<HTML><BODY>Error, no comments were submitted!"); print("</BODY></HTML>"); } } $msg = "Mass email sent"; header("Location: send-mass-email.php?msg=$msg"); } else { $query5 = mysql_query("SELECT * FROM aarbookts_booking_bookings WHERE id = '$id'"); $row5 = mysql_fetch_array($query5); $customer_name = $row5['customer_name']; $EmailBody = filter_input(INPUT_POST, 'EmailBody', FILTER_SANITIZE_STRING); $to = $row5['customer_email']; $from_header = "From: [email protected]\r\n"; $from_header .= "Reply-To: ". strip_tags($to) . "\r\n"; $from_header .= "MIME-Version: 1.0\r\n"; $from_header .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; $EmailBody1 = '<html><body>'; $EmailBody1 .= '<p><strong>Dear '.$customer_name.'</strong></p>'; $EmailBody1 .= '<p>'.$EmailBody.'</p>'; $EmailBody1 .= '</body></html>'; $EmailTitle = 'Subject'; if($EmailBody != "") { //send mail - $subject & $contents come from surfer input mail($to, $EmailTitle, $EmailBody1, $from_header); // redirect back to url visitor came from $msg = "Mass email sent"; header("Location: send-mass-email.php?msg=$msg"); } else { print("<HTML><BODY>Error, no comments were submitted!"); print("</BODY></HTML>"); } } mysql_close($link); ?> Please help? Quote Link to comment https://forums.phpfreaks.com/topic/243909-problem-with-my-email-script/ Share on other sites More sharing options...
WebStyles Posted August 5, 2011 Share Posted August 5, 2011 what EXACTLY does not work? post / explain the errors you're getting please. Quote Link to comment https://forums.phpfreaks.com/topic/243909-problem-with-my-email-script/#findComment-1252443 Share on other sites More sharing options...
jarv Posted August 5, 2011 Author Share Posted August 5, 2011 sorry, there are no errors, i think it just posts to ID 1 all the time?! Quote Link to comment https://forums.phpfreaks.com/topic/243909-problem-with-my-email-script/#findComment-1252448 Share on other sites More sharing options...
jarv Posted August 5, 2011 Author Share Posted August 5, 2011 sorry, I think it's working, emails were going to JUNK Quote Link to comment https://forums.phpfreaks.com/topic/243909-problem-with-my-email-script/#findComment-1252457 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.