douliedai4838 2011-03-25 11:42
浏览 64
已采纳

在PHP中发送邮件时警报不起作用

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";
?>
  • 写回答

3条回答 默认 最新

  • doutan3040 2011-06-01 03:55
    关注

    Dont know the same code is running for me now...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题