PHP 邮件功能不适用于 jQuery 验证插件

发布于 2024-12-26 02:40:42 字数 2794 浏览 1 评论 0原文

我有一个联系表格,效果很好。不过,我正在尝试使用 jQuery 验证插件 来检查是否有提交之前没有留下任何空白字段,但是当我添加插件时,我不再收到任何电子邮件。

代码如下:

内部 contact.html

$(document).ready(function(){
    $("form").validate({
    submitHandler: function() {
        alert("Thank you for submitting your information.");
        },
    });
});
<form class="cmxform" id="myform" method="post" action="contact.php">
    <fieldset>
        <p><label for="cname">Name:</label> <input type="text" id="cname" name="name" maxlength="255" class="required" /></p>
        <p><label for="cemail">Email:</label> <input type="text" id="cemail" name="email" maxlength="255" class="required email" /></p>
        <p><label for="tel">Tel:</label> <input type="text" id="tel" name="tel" maxlength="15" class="required" /></p>
        <p><label for="service">Service:</label>
            <select name="service">
                <option value="option1">Option1</option>
                <option value="option2">Option2</option>
                <option value="option3">Option3</option>
            </select>
        </p>
        <p><label for="comments">Comments:</label><textarea class="textarea" id="comments" name="comments" rows="7" cols="1"></textarea></p>

        <input type="submit" name="submit" class="button" value="Submit" />
    </fieldset>
</form>

和内部 contact.php

<?php
if(isset($_POST['submit']))
{
$name = $_POST['name'];
$email = $_POST['email'];
$tel = $_POST['tel'];
$service = $_POST['service'];
$comments = $_POST['comments'];

$header='From: '.$email."\r\n";
$header.='Content-Type: text/plain; charset=utf-8';

$msg='Message from: '.$name."\r\n";
$msg.='Email: '.$email."\r\n";
$msg.='Tel: '.$tel."\r\n";
$msg.='Interested in: '.$service."\r\n";
$msg.='Message: '.$comments."\r\n";
$msg.='Sent '.date("d/m/Y",time());
$msg.=utf8_decode('');

$to = '[email protected], [email protected], [email protected]';
$subject = 'Contact from website';

mail($to,$subject,$msg,$header);
}

header("Location: contact.html");
?>

我不知道插件需要进行哪些更改才能使用 PHP 邮件功能。如果有人能看一下并帮助我解决这个问题,我将不胜感激。提前致谢!

I have a contact form that works fine. However I'm trying to use the jQuery validation plugin to check that there are no empty fields left before submitting, but when I add the plugin I no longer receive any emails.

The code is as follows:

Inside contact.html

$(document).ready(function(){
    $("form").validate({
    submitHandler: function() {
        alert("Thank you for submitting your information.");
        },
    });
});
<form class="cmxform" id="myform" method="post" action="contact.php">
    <fieldset>
        <p><label for="cname">Name:</label> <input type="text" id="cname" name="name" maxlength="255" class="required" /></p>
        <p><label for="cemail">Email:</label> <input type="text" id="cemail" name="email" maxlength="255" class="required email" /></p>
        <p><label for="tel">Tel:</label> <input type="text" id="tel" name="tel" maxlength="15" class="required" /></p>
        <p><label for="service">Service:</label>
            <select name="service">
                <option value="option1">Option1</option>
                <option value="option2">Option2</option>
                <option value="option3">Option3</option>
            </select>
        </p>
        <p><label for="comments">Comments:</label><textarea class="textarea" id="comments" name="comments" rows="7" cols="1"></textarea></p>

        <input type="submit" name="submit" class="button" value="Submit" />
    </fieldset>
</form>

And inside contact.php

<?php
if(isset($_POST['submit']))
{
$name = $_POST['name'];
$email = $_POST['email'];
$tel = $_POST['tel'];
$service = $_POST['service'];
$comments = $_POST['comments'];

$header='From: '.$email."\r\n";
$header.='Content-Type: text/plain; charset=utf-8';

$msg='Message from: '.$name."\r\n";
$msg.='Email: '.$email."\r\n";
$msg.='Tel: '.$tel."\r\n";
$msg.='Interested in: '.$service."\r\n";
$msg.='Message: '.$comments."\r\n";
$msg.='Sent '.date("d/m/Y",time());
$msg.=utf8_decode('');

$to = '[email protected], [email protected], [email protected]';
$subject = 'Contact from website';

mail($to,$subject,$msg,$header);
}

header("Location: contact.html");
?>

I don't know what changes are required for the plugin to work with PHP mail function. I'd appreciate if someone can take a look and help me figure this out. Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

那一片橙海, 2025-01-02 02:40:42

当然 PHP 没有任何关系。我在submitHandler函数上缺少form.submit();。感谢 jprofitt 和 Kai Qing。

Certainly PHP had nothing to do. I was missing form.submit(); on the submitHandler function. Thanks to jprofitt and Kai Qing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文