简体   繁体   中英

My Contact Form sending blank emails

My contact form is sending blank emails most of the time, I have tried couple of changes but still result is same. My code is as follows:

HTML CODE:

<form action="mail.php" method="POST">
    <div class="form-group">
        <input type="text" name="name" class="form-control input-text" id="name" placeholder="Your Name" data-rule="minlen:4" data-msg="Please enter at least 4 chars" />
        <div class="validation"></div>
    </div>
    <div class="form-group">
        <input type="email" class="form-control input-text" name="email" id="email" placeholder="Your Email" data-rule="email" data-msg="Please enter a valid email" />
        <div class="validation"></div>
    </div>
    <div class="form-group">
        <input type="text" class="form-control input-text" name="subject" id="subject" placeholder="Subject" data-rule="minlen:4" data-msg="Please enter at least 8 chars of subject" />
        <div class="validation"></div>
    </div>
    <div class="form-group">
        <textarea class="form-control input-text text-area" name="message" rows="5" data-rule="required" data-msg="Please write something for us" placeholder="Message"></textarea>
        <div class="validation"></div>
    </div>

    <div class="text-center"><button type="submit" class="input-btn" onclick="select(this.id)">Send Message</button></div>
</form>

PHP Code:

<?php
 header('Location: index.php');
 $name = $_POST['name'];
 $email = $_POST['email'];
 $subject = $_POST['subject'];
 $message = $_POST['message'];
 $formcontent="From: $name \n Subject: $subject \n Message: $message";
 $recipient = "bassam.sheikh@vl-s.com";
 $subject = "Contact Form";
 $mailheader = "From: $email \r\n";
 mail($recipient, $subject, $formcontent, $mailheader);
?>

In mail function lines should be shorter than 70 characters, with your code you don't guarantee they are. Also line break should be "\\r\\n" not "\\n". Use this before mail:

$message= wordwrap("Message: $message", 70, "\r\n");
$formcontent="From: $name \r\n Subject: $subject \r\n $message";

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