I have an email form whose code is as follows:
(Live site).
<link href="https://antimalwareprogram.co/oxygen%20/template/css/responsive.css" rel="stylesheet">
<link id="css-preset" href="https://antimalwareprogram.co/oxygen%20/template/css/presets/preset1.css" rel="stylesheet">
<link href="https://antimalwareprogram.co/oxygen%20/template/css/main.css" rel="stylesheet">
<link href="https://antimalwareprogram.co/oxygen%20/template/css/bootstrap.min.css" rel="stylesheet">
<link href="https://antimalwareprogram.co/oxygen%20/template/css/lightbox.css" rel="stylesheet">
<link href="https://antimalwareprogram.co/oxygen%20/template/css/font-awesome.min.css" rel="stylesheet">
<link href="https://antimalwareprogram.co/oxygen%20/template/css/animate.min.css" rel="stylesheet">
<link href='https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700' rel='stylesheet' type='text/css'>
<script type="text/javascript" src="https://antimalwareprogram.co/oxygen%20/template/js/jquery.js"> </script>
<script type="text/javascript" src="https://antimalwareprogram.co/oxygen%20/template/js/bootstrap.min.js"> </script>
<script type="text/javascript" src="https://antimalwareprogram.co/oxygen%20/template/js/jquery.inview.min.js"></script>
<script type="text/javascript" src="https://antimalwareprogram.co/oxygen%20/template/js/wow.min.js"> </script>
<script type="text/javascript" src="https://antimalwareprogram.co/oxygen%20/template/js/mousescroll.js"></script>
<script type="text/javascript" src="https://antimalwareprogram.co/oxygen%20/template/js/smoothscroll.js"> </script>
<script type="text/javascript" src="https://antimalwareprogram.co/oxygen%20/template/js/jquery.countTo.js"> </script>
<script type="text/javascript" src="https://antimalwareprogram.co/oxygen%20/template/js/lightbox.min.js"> </script>
<script type="text/javascript" src="https://antimalwareprogram.co/oxygen%20/template/js/main.js"></script>
<script src="https://cdn.ckeditor.com/4.7.2/full-all/ckeditor.js"> </script>
<script src="https://antimalwareprogram.co/ckeditor/config.js"></script>
<script src="https://ajax.microsoft.com/ajax/jquery.validate/1.7/jquery.validate.min.js"></script>
<!--Email CORRECT Response!-->
<script type='text/javascript'>//<![CDATA[
$(window).load(function(){
$("#f3").validate({
rules: {
cktext: {
required: true,
minlength: 10
}
},
submitHandler: function () {
console.log('successful submission! Email sent to us! Thank you for choosing to submit a ticket to antimalwareprogram we will get back to you asap!');
alert('successful submission! Email sent to us! Thank you for choosing to submit a ticket to antimalwareprogram we will get back to you asap!');
}
});
//deal with copying the ckeditor text into the actual textarea
CKEDITOR.on('instanceReady', function () {
$.each(CKEDITOR.instances, function (instance) {
CKEDITOR.instances[instance].document.on("keyup", CK_jQ);
CKEDITOR.instances[instance].document.on("paste", CK_jQ);
CKEDITOR.instances[instance].document.on("keypress", CK_jQ);
CKEDITOR.instances[instance].document.on("blur", CK_jQ);
CKEDITOR.instances[instance].document.on("change", CK_jQ);
});
});
function CK_jQ() {
for (instance in CKEDITOR.instances) {
CKEDITOR.instances[instance].updateElement();
}
}
});//]]>
</script>
<?php
//if "email" variable is filled out, send email
if (isset($_REQUEST['email'])) {
//Email information
$admin_email = "support@antimalwareprogram.com";
$email = $_REQUEST['email'];
$subject = $_REQUEST['subject'];
$Message = $_REQUEST['cktext'];
$ItemAddress = $_REQUEST['ItemAddress'];
$ItemAddress2 = $_REQUEST['ItemAddress2'];
$ItemCity = $_REQUEST['ItemCity'];
$ItemState = $_REQUEST['ItemState'];
$ItemZip = $_REQUEST['ItemZip'];
$Size = $_REQUEST['Size'];
$Location = $_REQUEST['Location'];
$body = " Name: $name\n E-Mail: $email\n Email Body: $Message\n Location Entered: $Location\n Address: $ItemAddress\n Address Line 2: $ItemAddress2\n City: $ItemCity\n State: $ItemState\n Zip Code: $ItemZip";
//send
mail($admin_email, "$subject", $body, "From:" . $email);
//Email FAILED response
echo "<button class=\"btn btn-info\" onclick=\"myFunction()\">Return to AntiMalwareProgram</button>\n";
echo "\n";
echo "<script>\n";
echo "function myFunction() {\n";
echo " window.history.back();\n";
echo "}\n";
echo "</script>\n";
echo "<script>console.log('Thank you for choosing to submit a support ticket to antimalwareprogram! How ever there has been a error! Currently there is only one know cause to this issue, you must have pressed the save button on the email body message! Please use the send button and resubmit your ticket! We are very sorry!');</script>\n";
echo "<script>alert('Error: press ok for more info!');</script>\n";
echo "\n";
echo " <link rel=\"stylesheet\" href=\"https://cdnjs.cloudflare.com/ajax/libs/twitter- bootstrap/2.3.2/css/bootstrap.css\">\n";
echo " <link rel=\"stylesheet\" href=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css \">\n";
echo " <script src=\"https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js\"></script>\n";
echo " <script src=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js\"></script>\n";
echo " <link rel=\"stylesheet\" href=\"https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.2/css/bootstrap.css\">\n";
echo "<style type=\"text/css\">\n";
echo " #message {\n";
echo " position: fixed;\n";
echo " top: 50px;\n";
echo " left: 0;\n";
echo " width: 100%;\n";
echo "}\n";
echo "#inner-message {\n";
echo " margin: 0 auto;\n";
echo "}\n";
echo " </style>\n";
echo "\n";
echo "<div id=\"message\">\n";
echo " <div style=\"padding: 5px;\">\n";
echo " <div id=\"inner-message\" class=\"alert alert-danger\">\n";
echo " <strong>Error in sending of message! Details:</strong> Thank you for choosing to submit a support ticket to antimalwareprogram! How ever there has been a error! Currently there is only one know cause to this issue, you must have pressed the save button on the email body message! Please use the send button and resubmit your ticket! We are very sorry!\n";
echo " </div>\n";
echo " </div>\n";
echo "</div>\n";
}
//if "email" variable is not filled out, display the form
else {
?>
<form method="post" name="f3" id="f3">
<input name="subject" type="text" class="form-control" placeholder="Email Subject" autocomplete="off" required="required"/>
<input name="name" type="text" class="form-control" placeholder="Name" required="required"/>
<input type="email" name="email" class="form-control" placeholder="Email Address" required="required">
<!DOCTYPE html>
<html>
<body>
<label for="cktext">Email Body!</label>
<textarea class="ckeditor" name="cktext" id="cktext" placeholder="Email Body!"></textarea>
</body>
</html>
<button type="submit" class="btn-submit">Send! </button>
</form>
<?php
}
?>
What I'm trying to do is show a error message:
//Email FAILED response
echo "<button class=\"btn btn-info\" onclick=\"myFunction()\">Return to AntiMalwareProgram</button>\n";
echo "\n";
echo "<script>\n";
echo "function myFunction() {\n";
echo " window.history.back();\n";
echo "}\n";
echo "</script>\n";
echo "<script>console.log('Thank you for choosing to submit a support ticket to antimalwareprogram! How ever there has been a error! Currently there is only one know cause to this issue, you must have pressed the save button on the email body message! Please use the send button and resubmit your ticket! We are very sorry!');</script>\n";
echo "<script>alert('Error: press ok for more info!');</script>\n";
echo "\n";
echo " <link rel=\"stylesheet\" href=\"https://cdnjs.cloudflare.com/ajax/libs/twitter- bootstrap/2.3.2/css/bootstrap.css\">\n";
echo " <link rel=\"stylesheet\" href=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css \">\n";
echo " <script src=\"https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js\"></script>\n";
echo " <script src=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js\"> </script>\n";
echo " <link rel=\"stylesheet\" href=\"https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.2/css/bootstrap.css\">\n";
echo "<style type=\"text/css\">\n";
echo " #message {\n";
echo " position: fixed;\n";
echo " top: 50px;\n";
echo " left: 0;\n";
echo " width: 100%;\n";
echo "}\n";
echo "#inner-message {\n";
echo " margin: 0 auto;\n";
echo "}\n";
echo " </style>\n";
echo "\n";
echo "<div id=\"message\">\n";
echo " <div style=\"padding: 5px;\">\n";
echo " <div id=\"inner-message\" class=\"alert alert-danger\">\n";
echo " <strong>Error in sending of message! Details:</strong> Thank you for choosing to submit a support ticket to antimalwareprogram! How ever there has been a error! Currently there is only one know cause to this issue, you must have pressed the save button on the email body message! Please use the send button and resubmit your ticket! We are very sorry!\n";
echo " </div>\n";
echo " </div>\n";
echo "</div>\n";
This error message should only appear when the save button on my ckeditor is pressed or the email fails delivery! And i want to show this success message:
submitHandler: function () {
console.log('successful submission! Email sent to us! Thank you for choosing to submit a ticket to antimalwareprogram we will get back to you asap!');
alert('successful submission! Email sent to us! Thank you for choosing to submit a ticket to antimalwareprogram we will get back to you asap!');
}
});
That should appear on successful delivery of email and only on the send button press else send the failed response.
This doesn't work. I get the alert('successful submission! Email sent to us! Thank you for choosing to submit a ticket to antimalwareprogram we will get back to you asap!');
but that doesn't mean message sent. In fact it means it didn't, my email only sends if the save button on the ckeditor is pressed, which is the opposite of what I want. Is there a way to fix this?