dsdt66064367 2010-01-27 23:39
浏览 49

jQuery / AJAX / PHP表单“正常工作”,但没有发送电子邮件

It's not a problem with my host or the email account it's supposed to be delivered to: these things I've narrowed down. The form worked perfectly for one day and then stopped, without any changes to my code. Does anybody have any input on this?

My code:

Plug-In: http://www.stephaniehenderson.com/jquery.form.js

In the head:

<script type="text/javascript">
    $(document).ready(function () {
        var options = {
            target: '#alert'
        };
        $('#contactForm').ajaxForm(options);
    });

    $.fn.clearForm = function () {
        return this.each(function () {
            var type = this.type,
                tag = this.tagName.toLowerCase();
            if (tag == 'form')
                return $(':input', this).clearForm();
            if (type == 'text' || type == 'password' || tag == 'textarea')
                this.value = '';
            else if (type == 'checkbox' || type == 'radio')
                this.checked = false;
            else if (tag == 'select')
                this.selectedIndex = -1;
        });
    };
</script>    

Actual Form:

<form id="contactForm" method="post" action="sendmail.php"> 

<fieldset> 

<p>Email Me</p> 
<div id="fieldset_container"> 
<label for="name">Your Name:</label> 
<input type="text" name="name" id="name" /><br /><br /> 

<label for="email">Email:</label> 
<input type="text" name="email" id="email" /><br /><br /> 

<span style="display:none;"> 
<label for="last">Honeypot:</label> 
<input type="text" name="last" value="" id="last" /> 
</span><br /><br /> 

<label for="message">Comments &amp; Inquiries:</label> 
<textarea name="message" id="message" cols="" rows=""></textarea><br/> 
</div> 
<div id="submit_button"> 
<input type="submit" name="submit" id="submit" value="Send It" /> 
</div> 
</fieldset> 

</form> 

<div class="message"><div id="alert"></div></div>

sendmail.php:

<?php
$sendto = 'mypersonal@emailaddress.com';

$subject = 'SH Contact Form';

$errormessage = 'There seems to have been a problem. May I suggest...';

$thanks = "Thanks for the email!";

 //        Message for the bot when it fills in in at all.
$honeypot = "You filled in the honeypot! If you're human, try again!";

//        Various messages displayed when the fields are empty.
$emptyname =  'Entering your name?';
$emptyemail = 'Entering your email address?';
$emptymessage = 'Entering a message?';

//       Various messages displayed when the fields are incorrectly formatted.
$alertname =  'Entering your name using only the standard alphabet?';
$alertemail = 'Entering your email in this format: <i>name@example.com</i>?';
$alertmessage = "Making sure you aren't using any parenthesis or other escaping     characters in the message? Most URLS are fine though!";


//Setting used variables.
$alert = '';
$pass = 0;

// Sanitizing the data, kind of done via error messages first. Twice is better!  ;-)
function clean_var($variable) {
    $variable = strip_tags(stripslashes(trim(rtrim($variable))));
    return $variable;
}

//The first if for honeypot.
if ( empty($_REQUEST['last']) ) {

    // A bunch of if's for all the fields and the error messages.
    if ( empty($_REQUEST['name']) ) {
        $pass = 1;
        $alert .= "<li>" . $emptyname . "</li>";
    } elseif ( ereg( "[][{}()*+?.\\^$|]", $_REQUEST['name'] ) ) {
        $pass = 1;
        $alert .= "<li>" . $alertname . "</li>";
    }
    if ( empty($_REQUEST['email']) ) {
        $pass = 1;
        $alert .= "<li>" . $emptyemail . "</li>";
    } elseif ( !eregi("^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-  z]{2,3})$", $_REQUEST['email']) ) {
        $pass = 1;
        $alert .= "<li>" . $alertemail . "</li>";
    }
    if ( empty($_REQUEST['message']) ) {
        $pass = 1;
        $alert .= "<li>" . $emptymessage . "</li>";
    } elseif ( ereg( "[][{}()*+?\\^$|]", $_REQUEST['message'] ) ) {
        $pass = 1;
        $alert .= "<li>" . $alertmessage . "</li>";
    }

    //If the user err'd, print the error messages.
    if ( $pass==1 ) {

        //This first line is for ajax/javascript
        echo "<script>$(\".message\").hide(\"slow\").show(\"slow\"); </script>";
        echo "<b>" . $errormessage . "</b>";
        echo "<ul>";
        echo $alert;
        echo "</ul>";

    // If the user didn't err and there is in fact a message, time to email it.
    } elseif (isset($_REQUEST['message'])) {

        //Construct the message.
        $message = "From: " . clean_var($_REQUEST['name']) . "
";
        $message .= "Email: " . clean_var($_REQUEST['email']) . "
";
        $message .= "Message: 
" . clean_var($_REQUEST['message']);
        $header = 'From:'. clean_var($_REQUEST['email']);

        //Mail the message - for production
        mail($sendto, $subject, $message, $header, "-fstephanie@stephaniehenderson.com");
        //This is for javascript, 
        echo   "<script>$(\".message\").hide(\"slow\").show(\"slow\").animate({opacity: 1.0},        4000).hide(\"slow\"); $(':input').clearForm() </script>";
        echo $thanks;
        die();

        //Echo the email message - for development
        echo "<br/><br/>" . $message;

    }

//If honeypot is filled, trigger the message that bot likely won't see.
} else {
    echo "<script>$(\".message\").hide(\"slow\").show(\"slow\"); </script>";
    echo $honeypot;
}
?>
  • 写回答

2条回答 默认 最新

  • douwuying4709 2010-01-28 04:10
    关注

    sometimes mail() function in php is delayed... just make sure it is returning true and you have no problem.

    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么