我的联系表格发送空白电子邮件

时间:2018-06-03 09:56:45

标签: php html

我的联系表单大部分时间都在发送空白电子邮件,我尝试过几次更改,但结果仍然相同。我的代码如下:

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代码:

<?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);
?>

1 个答案:

答案 0 :(得分:-1)

在邮件功能行中应该短于70个字符,你不能保证你的代码。换行也应该是“\ r \ n”而不是“\ n”。在邮件之前使用它:

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