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

报告相同问题?

悬赏问题

  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码