I have a code that send an email but how I can prevent it from always sending everytime my page refreshes.
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 MW ITSM Tasks - "'.date('d-m-Y h:m:s').'"';
$mail->WordWrap = 100;
$mail->IsHTML(true);
$mail->Body = $Body;
$mail->Send();
}
I tried using this but it does not work,
if(!$mail->Send()) {
header("Location: http://www.example.com");
exit;
}