简体   繁体   English

为什么只发送一半的表格?

[英]Why is only half of my form sent?

I am trying to use post to send a form to my email address. 我正在尝试使用邮政将表格发送到我的电子邮件地址。 It is kind of working, I am getting the name and message. 这是一种工作,我得到了名字和消息。 Someone helped me with the part that is working, but when I try to add to it, what I added is not sent. 有人帮助我处理了正在运行的部分,但是当我尝试添加到该部分时,添加的内容不会发送。

I added a phone number and bid to it. 我添加了一个电话号码并出价。 That is the first one below. 那是下面的第一个。 I tried something else, I have seen something on here as well that did not work at all. 我尝试了其他方法,在这里也看到了一些根本不起作用的东西。

<form action="myform.php" method="POST">
    <p>Name</p> <input type="text" name="name">
    <p>Email</p> <input type="text" name="email">
    <p>Phone number</p> <input type="text" name="phone">
    <p>Your bid</p> <input type="text" name="bid">
    <p>Message</p>
    <textarea style="width:475px; height:175px;margin-left:7%"  name="message"></textarea><br/>
    <input type="submit" value="Send"><input type="reset" value="Clear">
</form>

$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message']; //line 5 $message now set
$phone = $_POST['phone'];
$bid = $_POST['bid'];
$formcontent="From: $name \n Message: $message" \n Phone  number:  $phone \n Your bid: $bid";
$recipient = "myemail";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";

update this is what i have http://jsfiddle.net/k8U3r/ 更新这是我拥有的http://jsfiddle.net/k8U3r/

I tried this too: 我也尝试过这个:

<?php

$name = $_POST['name']; //required
$phone = $_POST['phone']; //required
$bid = $_POST['bid']; //required
$message = $_POST['message']; //required


$formcontent .= " Name: $name \n";
$formcontent .= "Email Address: $email \n";
$formcontent .= "Phone Number: $phone \r\n";
$formcontent .= "Bid: $bid \n";
$formcontent .= " Message: $message \n";
$recipient = "myemail.com";
?>

You have incorrect syntax. 您的语法不正确。 The formcontent line should be formcontent行应为

$formcontent = "From: $name \n Message: $message \n Phone  number:  $phone \n Your bid: $bid";

You just need to remove the extra quote: 您只需要删除多余的报价:

$formcontent="From: $name \n Message: $message" \n Phone  number:  $phone \n Your bid: $bid";                                            
                                              ^

UPDATE: Another fix based on comments below: 更新:另一个基于以下注释的修复程序:

You need to define the PHP tags, otherwise it will interpret the php as HTML and just print it out. 您需要定义PHP标记,否则它将把php解释为HTML并将其打印出来。

    ...
    <textarea style="width:475px; height:175px;margin-left:7%"  name="message"></textarea><br/>
    <input type="submit" value="Send"><input type="reset" value="Clear">
</form>

<?php // Tag here

$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message']; //line 5 $message now set
$phone = $_POST['phone'];
$bid = $_POST['bid'];
$formcontent="From: $name \n Message: $message \n Phone  number:  $phone \n Your bid: $bid";
$recipient = "myemail";

?> // And here

in your first code, the $phone and $bid variables are not defined. 在您的第一个代码中,未定义$phone$bid变量。

$phone = $_POST['phone'];
$bid = $_POST['bid'];

And you should remove the " after $message variable in line 14. Don't forget to check if your form data is set or you will encounter Undefined Variable Error Message . like this: 并且您应该在第14行的$message变量后删除" 。不要忘记检查表单数据是否已设置,否则将遇到Undefined Variable Error Message ,如下所示:

<?php

if ( isset($_POST['name']) && isset($_POST['email']) && isset($_POST['phone']) && isset($_POST['bid']) $& isset($_POST['message']) ) {
    // Send data...
}

?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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