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条)

报告相同问题?

悬赏问题

  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容