Html 提交表单时不显示变量
当我提交表格时,会向我的电子邮件地址发送一封电子邮件,并在表格中输入详细信息,但当我收到电子邮件时,数据为空,这是我的代码Html 提交表单时不显示变量,html,php,Html,Php,当我提交表格时,会向我的电子邮件地址发送一封电子邮件,并在表格中输入详细信息,但当我收到电子邮件时,数据为空,这是我的代码 <?php $form = '<form action="test2.php" method="POST"> <table width="300" style="border: 1px solid black;"> <tr> <td>Name <td><in
<?php
$form = '<form action="test2.php" method="POST">
<table width="300" style="border: 1px solid black;">
<tr>
<td>Name <td><input type="text" id="name">
<tr>
<td>Phone Number <td><input type="text" id="telephone">
<tr>
<td colspan="2">
<input type="submit" name="submit" value="submit"/></div>
</tr>
</table>';
echo $form;
$to = 'redacted@redacted.redacted';
$name = $_POST['name'];
$telephone = $_POST['telephone'];
$body = "<div>Name: $name <br>Telephone Number: $telephone<br></div>";
// subject
$subject = 'Call Back Requested';
// message
$message = $body;
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To:' . "\r\n";
$headers .= 'From: Call Back Request <contact-us-form@yellowgrid.co.uk>' . "\r\n";
if(isset($_POST['submit'])){
mail($to, $subject, $message, $headers);
}
?>
问题是当我提交表格时,我收到一封电子邮件,上面写着
姓名(无)
电话号码(无)
谁能告诉我哪里出了问题
提前谢谢
Adam您必须为输入指定
名称属性:
<input type="text" id="name" name="name">
<input type="text" id="telephone" name="telephone">
而不是
<input type="text" id="name">
<input type="text" id="telephone">
您必须为输入指定名称
属性:
<input type="text" id="name" name="name">
<input type="text" id="telephone" name="telephone">
而不是
<input type="text" id="name">
<input type="text" id="telephone">
快速浏览之后,您应该将$body换成read
$body = '<div>Name: ' . $name . '<br>Telephone Number: ' . $telephone . '<br></div>';
$body='Name:'$名字。”
电话号码:'$电话。”
';
试一试,看看它是否有效在快速浏览之后,您应该交换$body以阅读
$body = '<div>Name: ' . $name . '<br>Telephone Number: ' . $telephone . '<br></div>';
$body='Name:'$名字。”
电话号码:'$电话。”
';
试一试,看看它是否有效关闭标记时有很多错误。。使用echo显示整个html表单是一种不好的做法。。查看此代码:
<?php
extract($_POST);
if ( isset($submit) )
{
$to = 'adam.albison@yellowgrid.co.uk';
$body = "<div>Name: $name <br>Telephone Number: $telephone<br></div>";
$subject = 'Call Back Requested';
$message = $body;
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To:' . "\r\n";
$headers .= 'From: Call Back Request <contact-us-form@yellowgrid.co.uk>' . "\r\n";
mail($to, $subject, $message, $headers);
}
?>
<html>
<form action="test2.php" method="POST">
<table width="300" style="border: 1px solid black;">
<tr>
<td>Name </td>
<td> <input type="text" id="name" name="name" /> </td>
</tr>
<tr>
<td>Phone Number </td>
<td> <input type="text" id="telephone" name="telephone" /> </td>
</tr>
<tr>
<td colspan="2"> <input type="submit" name="submit" value="submit"/> </td>
</tr>
</form>
</html>
名称
电话号码
结束标记中有很多错误。。使用echo显示整个html表单是一种不好的做法。。查看此代码:
<?php
extract($_POST);
if ( isset($submit) )
{
$to = 'adam.albison@yellowgrid.co.uk';
$body = "<div>Name: $name <br>Telephone Number: $telephone<br></div>";
$subject = 'Call Back Requested';
$message = $body;
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To:' . "\r\n";
$headers .= 'From: Call Back Request <contact-us-form@yellowgrid.co.uk>' . "\r\n";
mail($to, $subject, $message, $headers);
}
?>
<html>
<form action="test2.php" method="POST">
<table width="300" style="border: 1px solid black;">
<tr>
<td>Name </td>
<td> <input type="text" id="name" name="name" /> </td>
</tr>
<tr>
<td>Phone Number </td>
<td> <input type="text" id="telephone" name="telephone" /> </td>
</tr>
<tr>
<td colspan="2"> <input type="submit" name="submit" value="submit"/> </td>
</tr>
</form>
</html>
名称
电话号码
干杯我知道我错过了什么干杯我知道我错过了什么