php表单只发送一个变量的电子邮件

时间:2017-08-19 22:04:17

标签: php html5

我正在将此代码用于我的表单,但它只发送一个变量,在这种情况下是" type"。什么似乎是我的错?

php

<?php
$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$type = $_POST['type'];
$message = $_POST['message'];
$formcontent=" From: $name \n subject: $subject \n email: $email \n  Type: $type \n Message: $message";
$recipient = "ashele@diloptic.co.za";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "We will call you as soon as possible!" . " -" . "<a href='contact.html' style='text-decoration:none;color:#ff0099;'> Return Home</a>";
?>

这是相应的html5代码

<form action="mail.php" method="post" role="form" class="contactForm">
    <div class="s-12 l-7"><input type="text" name="name" class="form-control" id="name" placeholder="Your Name" data-rule="minlen:4" data-msg="Please enter at least 4 chars" /></div>
    <div class="validation"></div>
    <div class="s-12 l-7"><input type="email" class="form-control" name="email" id="email" placeholder="Your Email" data-rule="email" data-msg="Please enter a valid email" /></div>
    <div class="validation"></div>
    <div class="s-12"><input type="text" class="form-control" name="subject" id="subject" placeholder="Subject" data-rule="minlen:4" data-msg="Please enter at cell number plus code" /></div>
    <div class="validation"></div>
    <div class="s-12 l-7"><p placeholder="Subject" data-rule="minlen:4">type
        <select name="type" size="1">
        <option value="update">Website Update</option>
        <option value="change">Information Change</option>
         <option value="addition">Information Addition</option>
             <option value="new">New Products</option>
         </select></p></div>
         <div class="validation"></div>
         <div class="s-12 l-7"><textarea class="form-control" name="message" id="message" rows="5" data-rule="required" data-msg="Please write something for us" placeholder="Message"></textarea><br/></div>
                <div class="validation"></div>
    <div class="s-12 m-6 l-4"><button type="submit" name="submit" value="submit" class="btn btn-primary btn-lg" required="required">Submit Message</button></div>
</form>

2 个答案:

答案 0 :(得分:0)

尝试使用以下方法打印出所有的post数组:

print_r($_POST);

我尝试了你的html表单并正确接收了所有参数。

答案 1 :(得分:0)

你去了!

<?php

    if (isset($_POST['submit'])) {
        $name        = $_POST['name'];
        $email       = $_POST['email'];
        $subject     = $_POST['subject'];
        $type        = $_POST['type'];
        $message     = $_POST['message'];
        $formcontent = " From: $name \n subject: $subject \n email: $email \n  Type: $type \n Message: $message";
        $recipient   = "ashele@diloptic.co.za";
        $subject     = "Contact Form";
        $mailheader  = "From: $email \r\n";

        if (!mail($recipient, $subject, $formcontent, $mail_header)) {
            echo "error";
        } else {

            echo "We will call you as soon as possible!" . " -" . "<a href='contact.html' style='text-decoration:none;color:#ff0099;'> Return Home</a>";
            print_r($_POST);

        }

    }

    ?>

经过测试并且工作正常。 示例可以在这里找到!

enter image description here

尝试一下,让我知道结果。总是很乐意提供帮助!

相关问题