While I'm just trying to pull up data from the db, as soon as the page shows up with the data it is already sending an email. How can I prevent it from sending the email right away. What I want to happen is I retrieved data from the db > shows it to a page > edit the page > update the db and send an email. This is the only point where I want an email to be sent out.
Here is my entire code,
<form action="assign_test1.php" method="post">
<?php
if(is_array($result)){
echo '
<fieldset>
<legend>Assign Ticket</legend>
<div>Changes will affect updated rows only.</div>
<p></p>
<table width=auto cellpadding=1px cellspacing=0px border=1 align=center id=assign>
<thead>
<tr>';
// column comment from DB as column header
foreach($result[0] as $key => $val){
echo '<th align=center>'.$colcomments[$key].'</th>';
}
echo '
</tr>
</thead>
<tbody>';
foreach($result as $row => $info){
echo '<tr>';
foreach($info as $key => $val){
if($key=='id'){
echo '<td title="'.$colcomments[$key].'">'.$val.'.<input type="hidden" name="'.$key.'['.$info['id'].']" value="'.$val.'" id="rowid_'.$val.'" /></td>';
}
else {
echo '<td title="'.$colcomments[$key].'"><input type="text" name="'.$key.'['.$info['id'].']" value="'.$val.'" /></td>';
}
}
echo '</tr>';
}
echo '
</tbody>
</table>
</fieldset>';
function two_dim_array_to_html_table($arr, $colcomments){
$ret = "<table border='1' width='auto' cellpadding='1px' cellspacing='0px' align='center'>\n";
$ret .= "\t<tr>\n";
foreach($arr[0] as $key => $val){
$ret .= "\t\t<th>".$colcomments[$key]."</th>\n";
}
$ret .= "\t</tr>\n";
foreach($arr as $row){
$ret .= "\t<tr>\n";
foreach($row as $column){
$ret .= "\t\t<td>".$column."</td>\n";
}
$ret .= "\t</tr>\n";
}
$ret .= "<table>\n";
return $ret;
}
if($result) {
$Body = "<html>\n"
. "<head>\n"
. "</head>\n"
. "<body>\n"
. two_dim_array_to_html_table($result, $colcomments)
. "</body>\n"
. "</html>\n";
//Setting up Mail
$mail = new PHPMailer();
if (EMAIL_USE_SMTP) {
// Set mailer to use SMTP
$mail->IsSMTP();
//useful for debugging, shows full SMTP errors
//$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
// Enable SMTP authentication
$mail->SMTPAuth = EMAIL_SMTP_AUTH;
// Enable encryption, usually SSL/TLS
if (defined(EMAIL_SMTP_ENCRYPTION)) {
$mail->SMTPSecure = EMAIL_SMTP_ENCRYPTION;
}
// Specify host server
$mail->Host = EMAIL_SMTP_HOST;
$mail->Username = EMAIL_SMTP_USERNAME;
$mail->Password = EMAIL_SMTP_PASSWORD;
$mail->Port = EMAIL_SMTP_PORT;
} else {
$mail->IsMail();
}
$mail->From = EMAIL_FROM_ADDRESS;
$mail->FromName = EMAIL_FROM_NAME;
$mail->AddAddress('test.test@domain.COM');
$mail->Subject = 'Daily Tasks - "'.date('d-m-Y').'"';
$mail->WordWrap = 100;
$mail->IsHTML(true);
$mail->Body = $Body;
if $mail->Send();
}
}
?>
<fieldset>
<legend>Select Date</legend>
<div>Select Date from and Date to</div>
<p></p>
<input type="date" name="from" id="from" value="<?=$date['from']; ?>" />
<input type="date" name="to" id="to" value="<?=$date['to']; ?>" />
<div><input type="submit" value="Submit" /></div>
</fieldset>
</form>