我正在尝试使用帖子将表单发送到我的电子邮件地址。它有点工作,我得到了名字和信息。有人帮我处理了正在工作的部分,但是当我尝试添加它时,我添加的内容没有被发送。
我添加了一个电话号码并出价。这是下面的第一个。我尝试了别的东西,我在这里也看到了一些根本不起作用的东西。
<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!";
更新这是我的http://jsfiddle.net/k8U3r/
我也试过了:
<?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";
?>
答案 0 :(得分:6)
语法不正确。 formcontent
行应为
$formcontent = "From: $name \n Message: $message \n Phone number: $phone \n Your bid: $bid";
您只需删除额外的引用:
$formcontent="From: $name \n Message: $message" \n Phone number: $phone \n Your bid: $bid";
^
更新:基于以下评论的另一个修复:
您需要定义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
答案 1 :(得分:0)
在您的第一个代码中,$phone
和$bid
变量未定义。
$phone = $_POST['phone'];
$bid = $_POST['bid'];
您应该删除第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...
}
?>