1

我非常接近完成这个小项目,我需要做的就是让我的联系表发送电子邮件。容易吧?不好笑

提交消息后,我已经关闭了联系表格,但没有发送电子邮件,想知道是否有人可以帮助我解决这个问题?我的代码如下:

http://madaxedesign.co.uk/dev/contact.php http://madaxedesign.co.uk/dev/

jQuery: var doSubmit = function (event) { var postData = jQuery('#submit_message').serialize();

      jQuery.ajax({
        type: "POST",
        url: '/dev/contact.php',
        data: postData
      }).done(function( html ) {
        alert(html);
      });
      event.preventDefault();
    };

        $(function () {
        $('#submit_message').submit(doSubmit);
    });

PHP:

        <?php
        $your_email = "maxlynn@madaxedesign.co.uk";
        $subject = "Email From Madaxe";
        $empty_fields_message = "<p>Please go back and complete all the fields in the form.</p>";
        $thankyou_message = "<p>Thank you. Your message has been sent. We Will reply as soon as possible.</p>";

        $name = stripslashes($_POST['txtName']);
        $email = stripslashes($_POST['txtEmail']);
        $message = stripslashes($_POST['txtMessage']);

        if (!isset($_POST['txtName'])) {

        ?>

        <form id="submit_message" class="hide_900">
            <div id="NameEmail"> 
                <div>
                    <label for="txtName">Name*</label> 
                    <input type="text" title="Enter your name" name="txtName" />
                </div> 
                <div>
                    <label for="txtEmail">Email*</label> 
                    <input  type="text" title="Enter your email address" name="txtEmail" />
                </div> 
            </div>
            <div id="MessageSubmit">
                <div> 
                    <textarea maxlength="1200" title="Enter your message" name="txtMessage"></textarea> 
                    <label for="txtMessage">Message</label>
                </div>
                <div class="submit"> 
                    <input type="submit" value="Submit" /></label>
                </div>
            </div> 
        </form> 
        <?php

        }

        elseif (empty($name) || empty($email) || empty($message)) {

        echo $empty_fields_message;

        }

        else {

            $referer = $_SERVER['HTTP_REFERER'];
            $this_url = "http://".$_SERVER['HTTP_HOST'].$_SERVER["REQUEST_URI"];
        if ($referer != $this_url) {
        echo "You do not have permission to use this script from another URL, nice hacking attempt ;p.";
        exit;
            }

        mail($your_email, $subject, $message, "From: $name <$email>");

        echo $thankyou_message;

            }

        ?>

谢谢你的帮助

4

2 回答 2

1

您应该调试您的代码以查看是否有任何错误或错误,然后在您的问题中包含错误以获得更好的帮助。但无论如何,快速浏览一下,您的 jQuery 中缺少一个分号:

       jQuery.ajax({
           url: '/contact.php',
           data: postData
       }).done(function (html) {
           alert(html);
       });
       event.preventDefault();
   }; // <-- HERE

而且您的 HTML 格式不正确:

<div class="submit"> 
      <input type="submit" value="Submit" /></label> <!-- HERE the `label` -->
</div>

检查这两个并报告。恐怕它不能解决你的问题,但值得一试。

更新:

将此添加到您的 jQuery 中:

jQuery.ajax({
      type: "POST", // THIS
      url: '/contact.php',
      data: postData
      ...
于 2013-05-01T15:54:15.863 回答
0

使用了新的 PHP 并取出了我自己的 Jquery,现在必须想办法在我的弹出窗口中重定向感谢消息。谢谢你的帮助山姆

于 2013-05-03T15:06:41.993 回答