I have developed a simple php application. This application contains one html file and one php file. What i am doing is when user selects two dates and enters his/her email addresss, i am calling my php file which is sending the mail to entered email id.
It sends the mail correctly. But the problem is its not showing me the status whether mail is sent or not. I am using alert.
This is my html file :
<html>
<link rel="stylesheet" href="ui.all.css" type="text/css" media="screen" />
</head>
<body>
<label>Leave Application</label><br/>
From <input id="date" type="text" name="ndate" /><div id="d1"></div><br/>
To <input id="date1" type="text" name="ndate1" /><div id="d2"></div><br/>
Email To <input type="text" id="UserEmail" name="userEmail" onkeyup=""/><br/>
<input type="submit" id="btn_submit" value="Send" onclick="" />
<span id="d"></span>
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.5.3/jquery-ui.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#date").datepicker({ showOn: 'button', buttonImageOnly: true, buttonImage: 'Images/icon_cal.png' });
$("#date1").datepicker({ showOn: 'button', buttonImageOnly: true, buttonImage: 'Images/icon_cal.png' });
});
$("#btn_submit").click(function(event){
var hasError = false;
var dt1=$("#date").val();
var dt2=$("#date1").val();
var em=$("#UserEmail").val();
$(".error").hide();
if(dt1 == '')
{
$("#d1").before('<span class="error"><font color="red">This Field Must not be empty.</font></span>');
hasError = true;
}
if(dt2 == '')
{
$("#d2").before('<span class="error"><font color="red">This Field Must not be empty.</font></span>');
hasError = true;
}
var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
var emailaddressVal = $("#UserEmail").val();
if(emailaddressVal == '') {
$("#UserEmail").after('<span class="error"><font color="red">Please enter your email address.</font></span>');
hasError = true;
}
else if(!emailReg.test(emailaddressVal)) {
$("#UserEmail").after('<span class="error"><font color="red">Enter a valid email address.</font></span>');
hasError = true;
}
if(hasError == true) { return false; }
jQuery.ajax({
type: "GET",
url: "http://www.myserver.com/sent_mail.php",
async: false,
data: "dt1="+dt1+"&dt2="+dt2+"&email="+em,
success: function(msg){
alert(msg);
}
});
});
</script>
</body>
</html>
This is my php file :
<?php
`extract($_GET);`
$msg="Respected Sir,
\tI will not be able to come to office from ".$dt1." to ".$dt2.". Please grant my leave";
$pcto=$email;
$pcsubject = 'Leave Application';
$pcmessage = $msg;
$pcheaders = 'From:abc@abc.com'."
" .
'Reply-To: abc@abc.com'."
" .
'X-Mailer: PHP/' . phpversion();
$isdone=mail($pcto, $pcsubject, $pcmessage, $pcheaders);
if($isdone)
echo "Mail Sent";
else
echo "Please Try Again";
?>