Jump to content

problem with my email script?!


jarv

Recommended Posts

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@email.com\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@email.com\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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.