简体   繁体   中英

jquery validated form sends blank emails

The form works fine, if you fill it, it sends the email and if you don't fill all the inputs, it warns you that you must do it and won't send the form until you do it.

I'm using I'm using jquery.validate.js for this but lately, I've been getting Blank Emails. If the validate is working (I even tested in old browsers), why is it sending me blank emails?

HTML

<form id="contact-form" method="post" action="contacto.php">
                <fieldset>

                    <div class="control-group">
                        <div class="controls">
                            <input name="name" id="name" type="text" placeholder="Nombre" required> 
                        </div>
                    </div>

                    <div class="control-group" style="margin-top:10px;">
                        <div class="controls">
                            <input type="text" name="email" id="email" placeholder="Email" required>
                        </div>
                    </div>

                    <div class="control-group" style="margin-top:10px;">
                        <div class="controls">
                            <textarea class="input-xlarge" name="message" id="message" rows="3" placeholder="Mensaje"></textarea>
                        </div>
                    </div>

                <div class="form-actions">
                    <button type="submit" class="demo-pricing demo-pricing-1">Submit</button>
                    <button type="reset" class="demo-pricing demo-pricing-1">Cancel</button>
                </div>
            </fieldset>
        </form>

PHP

$subject = "Web";

$to = 'contact@web.com';
$header .= "Content-Type: text/html; charset=UTF-8";
$headers = "From: " . $_POST["name"]; 
$headers .= "<" . $_POST["email"] . ">\r\n"; 
$headers .= "Reply-To: " . $_POST["email"] . "\r\n"; 
$headers .= "Return-Path: " . $_POST["email"]; 

$message .= "************************************************** \n";
$message .= "Contact \n";
$message .= "************************************************** \n\n";  

$message .= "Nombre: " . $_POST["name"] . "\r";
$message .= "E-mail: " . $_POST["email"] . "\r";
$message .= "Mensaje: " . $_POST["message"] . "\r";

$mail_sent = mail($to, $subject, $message, $headers); 
if ($mail_sent == true){ ?>         <script language="javascript" type="text/javascript">         window.alert('behold, we are aware of you')
    window.location.href='index.html';         </script>     <?php } else { ?>     <script language="javascript" type="text/javascript">         alert('nope, try again');      </script>     <?php     } 

update: Turns out it was some issue with the server or so they told me, and there was nothing i could have done.

The fact that you are using a client side validation, doesn't assure that you will always receive valid inputs in the back-end. You should always do validation in your PHP script as well, irrespective of whether you do that in the browser. There may be cases when the user has JS disabled or even a maliciously framed request to your server side script.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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