从我的“联系我们”页面发送的电子邮件仅包含主题“来自我们的联系我们页面消息”以及正文消息的第一部分,例如来自:IGN:电子邮件:
看起来这些字段不起作用,但我不知道为什么。
这是我的联系我们php代码:
$mail_to = 'support@mineyc.com';
$subject = 'Contact Us page message from '.$field_name;
$body_message = 'From: '.$field_name."\n";
$body_message .= 'IGN: '.$field_ign."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;
$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";
$mail_status = mail($mail_to, $subject, $body_message, $headers);
if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message. We will contact you shortly.');
window.location = '/contactus.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please, send an email to support@mineyc.com');
window.location = '/contactus.html';
</script>
<?php
}
?>
以下是HTML代码:
<!-- Main Content -->
<div class="container">
<div class="well">
<div class="row">
<div class="col-lg-6">
<div class="well">
<form class="form-horizontal" action="/php/contact.php" method="post">
<fieldset>
<legend>Contact Us</legend>
<div class="form-group">
<label for="inputName" class="col-lg-2 control-label">Name</label>
<div class="col-lg-10">
<input type="text" class="form-control" id="inputName" placeholder="Name">
</div>
</div>
<div class="form-group">
<label for="inputIGN" class="col-lg-2 control-label">IGN</label>
<div class="col-lg-10">
<input type="text" class="form-control" id="inputIGN" placeholder="In-game Name">
</div>
</div>
<div class="form-group">
<label for="inputEmail" class="col-lg-2 control-label">Email</label>
<div class="col-lg-10">
<input type="text" class="form-control" id="inputEmail" placeholder="Email">
</div>
</div>
<div class="form-group">
<label for="textArea" class="col-lg-2 control-label">Message</label>
<div class="col-lg-10">
<textarea class="form-control" rows="3" id="textArea"></textarea>
<span class="help-block">Please enter a real email address so that we can reply to your message.</span>
</div>
</div>
<div class="form-group">
<div class="col-lg-10 col-lg-offset-2">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</fieldset>
</form>
</div>
</div>
</div>
</div>
某些地方肯定会有一些小错误,或者我在HTML中遗漏的东西。 提前感谢您的帮助。
答案 0 :(得分:0)
您的字段没有任何name
属性。提交表单时,不会将未命名的字段传递给PHP脚本。 Yopur输入需要name
属性,如下所示:
<input type="text" class="form-control" id="inputIGN" name="inputIGN" placeholder="In-game Name">
可以使用相同的id
和name
您的PHP脚本似乎没有尝试读取任何传递的变量,因此不清楚您希望表单数据如何到达电子邮件。
要阅读上面说明的输入,您可以使用:
$field_ign = $_POST['inputIGN'];
您需要为所有<input>
和<textarea>
答案 1 :(得分:0)
您的表单输入没有任何名称。在表单中命名每个输入以发布数据
<div class="container">
<div class="well">
<div class="row">
<div class="col-lg-6">
<div class="well">
<form class="form-horizontal" action="" method="post">
<legend>Contact Us</legend>
<div class="form-group">
<label for="inputName" class="col-lg-2 control-label">Name</label>
<div class="col-lg-10">
<input type="text" name="inputName" class="form-control" id="inputName" placeholder="Name">
</div>
</div>
<div class="form-group">
<label for="inputIGN" class="col-lg-2 control-label">IGN</label>
<div class="col-lg-10">
<input type="text" name="inputIGN" class="form-control" id="inputIGN" placeholder="In-game Name">
</div>
</div>
<div class="form-group">
<label for="inputEmail" class="col-lg-2 control-label">Email</label>
<div class="col-lg-10">
<input type="text" name="inputEmail" class="form-control" id="inputEmail" placeholder="Email">
</div>
</div>
<div class="form-group">
<label for="textArea" class="col-lg-2 control-label">Message</label>
<div class="col-lg-10">
<textarea class="form-control" rows="3" id="textArea"></textarea>
<span class="help-block">Please enter a real email address so that we can reply to your message.</span>
</div>
</div>
<div class="form-group">
<div class="col-lg-10 col-lg-offset-2">
<input type="submit" value="Save" name="submit"/>
</div>
</div>
</form>
</div>
</div>
</div>
</div>