dongqia3502 2014-02-24 19:03 采纳率: 100%
浏览 47
已采纳

Php邮件留在发送模式

When i try to send mail with the code the send button stays in "sending" and never changes to "sent". But mail is actuall sent to my mail box... You can check in site secco.uni.me Thanks.

The html code of main page:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>

<head>
<title>Sun and Moon Calculations</title>
<link rel="shortcut icon" href="site_icon.png">
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<meta name="robots" content="index,follow"> 
<meta name="description" content="Calculate local sunrise, sunset, moonrise, moonset and moon illumination with a click on map. Learn your time zone. Great tool for photographers and hunters as well as security forces. "> 
<link rel="stylesheet" type="text/css" href="secco.css"> 
<link href="fancybox/source/jquery.fancybox.css" media="all" type="text/css" rel="stylesheet">
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=AIzaSyD2rBJhT2rjQwA3jVKYrbbElkkm525UabU&sensor=false"></script>
<script type="text/javascript" src="map.js"></script>
<script type="text/javascript" src="time.js"></script>
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript" src="fancybox/source/jquery.fancybox.js?v=2.0.6"></script>
</head>

<body>
<img alt="Under Construction" src="ribbon.png" width="132" height="100" style="position: absolute; top: 0; right: 0; border: 0;">
<script src="moon.js"></script>
<center>
    <h2>Sun and Moon Calculations</h2>
    <div id="bd">
        <div id="gmap"></div>
        <!--Lat: <span id="lat"></span> Lon: <span id="lon"></span><br/>
        Zoom Level: <span id="zoom_level"></span> -->
    <div id="expl"><h5>*Click <span style="color:red">red</span> marker for exact coordinates.
        Center the map, then hit buttons for calculations. Your feedback is valuable...<h5></div>
    </div>
    <div id="form">
    <form name=calc>
        <table border="" cellspacing=5 bordercolor=white frame=void rules=rows>
        <tr>
            <td>Latitude  <td><INPUT size=20 maxLength=10 name=lat>
            <td>RAW Offset<td><INPUT readOnly size=35 maxLength=35 name=rawoffset>
            <td>Moonrise  <td><INPUT readOnly size=20 maxLength=20 name=moonrise>
        <tr>
            <td>Longitude <td><INPUT size=20 maxLength=20 name=lon>
            <td>DST Offset<td><INPUT readOnly size=35 maxLength=35 name=dstoffset>
            <td>Moonset<td><INPUT readOnly size=20 maxLength=20 name=moonset>
        <tr>
            <td>Zoom Level<td><INPUT readOnly size=20 maxLength=20 name=zl>
            <td>Time Zone ID <td><INPUT readOnly size=35 maxLength=35 name=timezoneid>
            <td>Moon Phase<td><INPUT readOnly size=20 maxLength=20 name=moonphase>
        <tr>
            <td>This Day  <td><INPUT readOnly size=20 maxLength=20 name=thisday>
            <td>Time Zone <td><INPUT readOnly size=35 maxLength=35 name=timezone>
        <tr>

        <td>Timestamp <td><INPUT readOnly size=20 maxLength=20 name=timestamp>

        </table>
    </form>
    </div>
    <input type="button" onclick="setLocation()" value="Set Location">
    <input type="button" onclick="compute()" value="Moon Calculation">
    <input type="button" onclick="sun()" value="Sun Calculation"><br>
</center>

<!-- Feedback mail post section-->
<!-- hidden inline form -->
<div id="inline">
    <h2>Send us a Message</h2>

    <form id="contact" name="contact" action="#" method="post">
        <label for="email">Your E-mail</label>
        <input type="email" id="email" name="email" class="txt">
        <br>
        <label for="msg">Enter a Message</label>
        <textarea id="msg" name="msg" class="txtarea"></textarea>

        <button id="send">Send E-mail</button>
    </form>
</div>
<script type="text/javascript" src="mailpost.js"></script>
<!-- BOTTOM STUFF -->
<div id="bottom">
<script language="JavaScript">
initdate();
var count = "secco";          // Change Your Account?
var type = "war2orc";       // Change Your Counter Image?
var digits = "7";          // Change The Amount of Digits on Your Counter?
var prog = "hit";          // Change to Either hit/unique?
var statslink = "no";    // provide statistical link in counter yes/no?
var sitelink = "yes";     // provide link back to our site;~) yes/no?
var cntvisible = "yes"; // do you want counter visible yes/no?
</script>
<!-- START DO NOT TAMPER WITH ANYTHING ELSE BELOW THIS LINE FOR YOUR WEBTV & UNIX VISITORS -->
<a href="http://jquery.com"><img src="jquery-logo.png" width="70" height="15" style="position: relative;width:95% text-align:left;top:3px; left:60px;"/></a>
<a href="http://maps.google.com"><img src="google-maps-api-v3.png" width="70" height="15" style="position: relative;width:95% text-align:left;top:3px; left:-90px;"/></a>
<a class = "modalbox" href="#inline"><img src="icon_mailto.gif" style="position: relative;width:95% text-align:right;top:3px; left:-8px;"/></a>
<script language="JavaScript" src="http://005.free-counters.co.uk/count-072.js">
</script>
<noscript>
<a href="http://www.free-counters.co.uk" target="_blank">
<img  src="http://005.free-counters.co.uk/count-072.pl?count=secco&cntvisible=no&mode=noscript" style="position: absolute;" alt="Free Counters" title="Free Counters" border="0">
</a>The following text will not be seen after you upload your website,
please keep it in order to retain your counter functionality 
<br><a href="http://www.free-counters.co.uk/trackers/" target="_blank">Trackers</a><br> <a href="http://www.free-counters.co.uk/help/counter/" target="_blank">Counter Help</a><br>
</noscript>
<!-- END DO NOT TAMPER WITH ANYTHING ELSE ABOVE THIS LINE FOR YOUR WEBTV & UNIX VISITORS -->
</div>
</CENTER>        
</body>
</html> 

My mailpost.js file:

function validateEmail(email) { 
        var reg = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
        return reg.test(email);
    }

    $(document).ready(function() {
        $(".modalbox").fancybox();
        $("#contact").submit(function() { return false; });


        $("#send").on("click", function(){
            var emailval  = $("#email").val();
            var msgval    = $("#msg").val();
            var msglen    = msgval.length;
            var mailvalid = validateEmail(emailval);

            if(mailvalid == false) {
                $("#email").addClass("error");
            }
            else if(mailvalid == true){
                $("#email").removeClass("error");
            }

            if(msglen < 4) {
                $("#msg").addClass("error");
            }
            else if(msglen >= 4){
                $("#msg").removeClass("error");
            }

            if(mailvalid == true && msglen >= 4) {
                // if both validate we attempt to send the e-mail
                // first we hide the submit btn so the user doesnt click twice
                $("#send").replaceWith("<em>sending...</em>");

                $.ajax({
                    type: 'POST',
                    url: 'sendmessage.php',
                    data: $("#contact").serialize(),
                    success: function(data) {
                        if(data == "true") {
                            $("#contact").fadeOut("fast", function(){
                                $(this).before("<p><strong>Success! Your feedback has been sent, thanks :)</strong></p>");
                                setTimeout("$.fancybox.close()", 1000);
                            });
                        }
                    }
                });
            }
        });
    });

And sendmessage.php file

<?php
$sendto   = "mail@hotmail.com";
$usermail = $_POST['email'];
$content  = nl2br($_POST['msg']);

$subject  = "New Feedback Message";
$headers  = "From: " . strip_tags($usermail) . "
";
$headers .= "Reply-To: ". strip_tags($usermail) . "
";
$headers .= "MIME-Version: 1.0
";
$headers .= "Content-Type: text/html;charset=utf-8 
";

$msg  = "<html><body style='font-family:Arial,sans-serif;'>";
$msg .= "<h2 style='font-weight:bold;border-bottom:1px dotted #ccc;'>New User Feedback</h2>
";
$msg .= "<p><strong>Sent by:</strong> ".$usermail."</p>
";
$msg .= "<p><strong>Message:</strong> ".$content."</p>
";
$msg .= "</body></html>";

if(@mail($sendto, $subject, $msg, $headers)) {
    echo "true";
} else {
    echo "false";
}

?>
  • 写回答

3条回答 默认 最新

  • dp411805872 2014-03-03 21:05
    关注

    PHP Code

    if(@mail($sendto, $subject, $msg, $headers)) {
        echo "1";
    } else {
        echo "0";
    }
    

    AJAX code:

    $.ajax({
                        type: 'POST',
                        url: 'sendmessage.php',
                        data: $("#contact").serialize(),
                        success: function(data) {
                            if(data == 1) {
                                $("#contact").fadeOut("fast", function(){
                                    $(this).before("<p><strong>Success! Your feedback has been sent, thanks :)</strong></p>");
                                    setTimeout("$.fancybox.close()", 1000);
                                });
                            }
                        }
                    });
    

    I changed the true and false echo responses to 0 and 1. I suppose there is a problem about js code about fetching the return from php code. Anyway the code runs as it is supposed to. Thanks.

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

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?