繁体   English   中英

Contactform无法正常工作

[英]Contactform not working as it should

我最近购买了一个模板,该模板包含带有ajax和验证的联系表格。 我尝试将自己的脚本应用于该脚本,但这无法正常工作。 它可能是服务器端的东西(我的脚本)。 有人看到我在做什么错吗?

这是联系页面上的表格:

<form class="contact-form" id="contact-form" method="post" action="contact_form/contact_form.php">
                <div class="row">
                    <fieldset class="column column-1-2">
                        <input class="text-input" name="name" type="text" placeholder="Naam *">
                        <input class="text-input" name="email" type="text" placeholder="Email *">
                        <input class="text-input" name="phone" type="text" placeholder="Telefoonnummer">
                        <input class="text-input" name="subject" type="text" placeholder="Onderwerp">
                    </fieldset>
                    <fieldset class="column column-1-2">
                        <textarea name="message" placeholder="Bericht *"></textarea>
                    </fieldset>
                </div>
                <div class="row margin-top-30">
                    <div class="column column-1-2">
                        <p>We nemen zo snel mogelijk contact met je op.</p>
                    </div>
                    <div class="column column-1-2 align-right">
                        <input type="hidden" name="action" value="contact_form" />
                        <div class="row margin-top-20 padding-bottom-20">
                            <a class="more submit-contact-form" href="#" title="SEND MESSAGE"><span>VERSTUUR</span></a>
                        </div>
                    </div>
                </div>
            </form>

这是ajax部分:

//contact form
    if($(".contact-form").length)
    {
        $(".contact-form").each(function(){
            $(this)[0].reset();
        });
        $(".submit-contact-form").on("click", function(event){
            event.preventDefault();
            $("#contact-form").submit();
        });
    }
    $(".contact-form").submit(function(event){
        event.preventDefault();
        var data = $(this).serializeArray();
        var self = $(this);
        //if($(this).find(".total-cost").length)
        //  data.push({name: 'total-cost', value: $(this).find(".total-cost").val()});
        self.find(".block").block({
            message: false,
            overlayCSS: {
                opacity:'0.3',
                "backgroundColor": "#FFF"
            }
        });

        $.ajax({
            url: self.attr("action"),
            data: data,
            type: "post",
            dataType: "json",
            success: function(json){
                self.find(".submit-contact-form, [name='submit'], [name='name'], [name='email'], [name='message']").qtip('destroy');
                if(typeof(json.isOk)!="undefined" && json.isOk)
                {
                    if(typeof(json.submit_message)!="undefined" && json.submit_message!="")
                    {
                        self.find(".submit-contact-form").qtip(
                        {
                            style: {
                                classes: 'ui-tooltip-success'
                            },
                            content: { 
                                text: json.submit_message 
                            },
                            position: { 
                                my: "right center",
                                at: "left center" 
                            }
                        }).qtip('show');
                        self[0].reset();
                        self.find(".cost-slider-input").trigger("change");
                        self.find(".cost-dropdown").selectmenu("refresh");
                        self.find("input[type='text'], textarea").trigger("focus").trigger("blur");
                    }
                }
                else
                {
                    if(typeof(json.submit_message)!="undefined" && json.submit_message!="")
                    {
                        self.find(".submit-contact-form").qtip(
                        {
                            style: {
                                classes: 'ui-tooltip-error'
                            },
                            content: { 
                                text: json.submit_message 
                            },
                            position: { 
                                my: "right center",
                                at: "left center" 
                            }
                        }).qtip('show');
                    }
                    if(typeof(json.error_name)!="undefined" && json.error_name!="")
                    {
                        self.find("[name='name']").qtip(
                        {
                            style: {
                                classes: 'ui-tooltip-error'
                            },
                            content: { 
                                text: json.error_name 
                            },
                            position: { 
                                my: "bottom center",
                                at: "top center" 
                            }
                        }).qtip('show');
                    }
                    if(typeof(json.error_email)!="undefined" && json.error_email!="")
                    {
                        self.find("[name='email']").qtip(
                        {
                            style: {
                                classes: 'ui-tooltip-error'
                            },
                            content: { 
                                text: json.error_email 
                            },
                            position: { 
                                my: "bottom center",
                                at: "top center" 
                            }
                        }).qtip('show');
                    }
                    if(typeof(json.error_message)!="undefined" && json.error_message!="")
                    {
                        self.find("[name='message']").qtip(
                        {
                            style: {
                                classes: 'ui-tooltip-error'
                            },
                            content: { 
                                text: json.error_message 
                            },
                            position: { 
                                my: "bottom center",
                                at: "top center" 
                            }
                        }).qtip('show');
                    }
                }
                self.find(".block").unblock();
            }
        });
    });

邮件脚本:

<?PHP
require '../PHPMailer/PHPMailerAutoload.php';
$isValid = true;
if(isset($_POST['name']) && isset($_POST['subject']) && isset($_POST['email']) && isset($_POST['message'])) 
{
    $name = $_POST['name'];
    $subject = 'Er is een contact aanvraag op website: '.$_POST['subject'];
    $email = $_POST['email'];
    $message = $_POST['message'];
    $phone = $_POST['phone'];
    $mail = new PHPMailer;
    $mail->From = $email;
    $mail->FromName = $name;
    $mail->addAddress("info@website.nl");     // Add a recipient
    $mail->isHTML(true);                      // Set email format to HTML
    $mail->Subject = $subject;
    $texts = 'Er is een aanvraag op de website van website<br /> <br />
    <b>Naam:</b> '.$name.'<br />
    <b>E-mail adres:</b> '.$email.'<br />
    <b>Onderwerp:</b> '.$subject.'<br />
    <b>Vragen / Opmerkingen:</b> '.$message.'<br /><br /><br />
    ';

    $handtekening = '
    <table border="0" width="100%" cellspacing="0" cellpadding="0" style="font-family:calibri;color: #5C5C5C; font-size:10pt;line-height:22px;">
    <tr>
    <td width="160" valign="top" style="font-family:calibri;padding-left:10px;padding-top:20px;">
    [contents]
    </td>
    </tr>
    <tr>
    <td width="160" valign="top" style="font-family:calibri;padding-left:10px;padding-top:20px;">
    <br><br>Met vriendelijke groet,<br><br>
    Helpdesk<br>
    <b>Website</b><br>
    <p></p>
    </td>
    </tr>
    </table>
    <table height="120" border="0" width="100%" cellspacing="0" cellpadding="0" style="font-family:calibri;color: #5C5C5C; font-size:10pt;line-height:22px;">
    <tr>
    <td width="250" valign="top" style="font-family:calibri;padding-left:10px;padding-top:20px;border-top: 1px #000000 dotted; border-bottom: 1px #000000 dotted;">
    E:&nbsp;&nbsp;
    <a href="mailto:info@website.nl" style="font-family:calibri;color: #5C5C5C; text-decoration: none; border-bottom: 1px #5C5C5C dotted;">info@website.nl</a><br>
    T:&nbsp;&nbsp;
    <a href="tel:0181851859" style="font-family:calibri;color: #5C5C5C; text-decoration: none; border-bottom: 1px #5C5C5C dotted;">(0181) 851 859</a><br>
    W:&nbsp;&nbsp;
    <a href="http://website.nl" style="font-family:calibri;color: #5C5C5C; text-decoration: none; border-bottom: 1px #5C5C5C dotted;" target="_blank">www.website.nl</a><br>
    </td>
    <td align="right" style="font-family:calibri;padding-right:10px;padding-top:5px;border-top: 1px #000000 dotted; border-bottom: 1px #000000 dotted;">
    <a href="http://website.nl/" target="_blank" title="Ga naar website">
    <img src="http://www.website.nl" alt="Ga naar website" style="font-family:calibri;text-align:right;margin:0px;padding:10px 0 10px 0;" border="0" width="232">
    </a>
    </td>
    </tr>
    <tr>
    <td colspan="2" style="font-family:calibri;color:#a3a3a3;font-size:11px;margin-top:6px;line-height:14px;">
    <br>Dit e-mailbericht is uitsluitend bestemd voor de geadresseerde. Als dit bericht niet voor u bestemd is, wordt u vriendelijk verzocht dit aan de afzender te melden. website staat door de elektronische verzending van dit bericht niet in voor de juiste en volledige overbrenging van de inhoud, noch voor tijdige ontvangst daarvan. Voor informatie over website raadpleegt u <a href="http://website.nl" style="font-family:calibri;color: #5C5C5C; text-decoration: none; border-bottom: 1px #5C5C5C dotted;" target="_BLANK">website</a>.<br><br>
    </td>
    </tr>
    </table>';

    $contents = preg_replace('/\[contents]/',$texts, $handtekening);
    $mail->msgHTML($contents);
    $mail->AltBody = $texts;
    if(!$mail->send()) 
    {
        $isValid = false;
    }

    $mail = new PHPMailer;
    $mail->From = 'info@website.nl';
    $mail->FromName = 'website';
    $mail->addAddress($email);     // Add a recipient
    $mail->isHTML(true);           // Set email format to HTML
    $mail->Subject = 'Bedankt voor uw aanvraag bij website';
    $texts = 'Geachte heer/mevrouw '.$naam.',<br /><br />
    Hartelijk dank voor uw aanvraag bij website<br />
    Wij reageren zo spoedig mogelijk op uw aanvraag.<br /><br />
    Uw gegevens worden nooit aan derden ter hand gesteld.
    ';
    $contents = preg_replace('/\[contents]/',$texts, $handtekening);
    $mail->msgHTML($contents);
    $mail->AltBody = $texts;
    if(!$mail->send()) {
    $isValid = false;
    }
    }else 
    {
        $isValid = false;
    }

    $array = array(
    'isValid' => $isValid
    );

    echo json_encode($array);

该脚本需要发送两个邮件。 一份给发送者作为确认,另一份给接收者。

验证无效。 我认为发送脚本缺少一些信息。

您提交带有ID联系人表格的表格

$("#contact-form").submit();

但是用

 $(".contact-form").submit(function(event){}

尝试将其更改为

 $("#contact-form").submit(function(event){}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM