【发布时间】:2017-11-20 17:42:55
【问题描述】:
我正在使用 HTML 和 PHP 创建一个简单的反馈表单。表单和脚本正在运行,我收到了提交的电子邮件,除了一个问题:
=> 我希望反馈表发送使用反馈表的页面的 URL,并在我的电子邮件中接收。我想知道用户正在谈论哪个页面。例如,如果用户单击反馈按钮并在http://example.com/features 页面上打开反馈表单(模式),我希望在我的电子邮件中包含该页面的 URL (http://example.com/features) 以及反馈消息。
这是我的 HTML 和 PHP:
HTML 表单:
<div id="myModal" class="modal">
<div id="modal-box" class="modal-content">
<div class="modal-header">
<span class="close">×</span>
<h2>Some Heading?</h2>
</div>
<div class="container">
<!--The submitt button in the form redirects action to the PHP script for message submission -->
<form action="http://example.com/mailer.php" role="form" name="feedbackForm" id="feedback_docs" method="post" >
<textarea id="comments" type="text" name="comments" placeholder="Please write your comments about this topic here." style="height:200px"></textarea>
<input id="submit" name="submit" type="submit" value="Send" />
</form>
</div>
</div>
</div>
<div id="myBtn">
<button id="popup" class="feedback-button">FEEDBACK</button>
<p id="demo"></p>
</div>
PHP:
<?php
$comments = $_POST['comments'];
$to = 'feedback@example.com';
$subject = 'Feedback received from website';
$url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['PATH_INFO'];
$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-type: text/html; charset=iso-8859-1';
$body = "Message: \r\r $comments";
if ($_POST['submit']) {
if (mail ($to, $subject, $url, $body)) {
echo '<p>Your message has been sent!</p>';
} else {
echo '<p>Something went wrong, go back and try again!</p>';
}
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
如果您查看 PHP 脚本,我尝试添加以下内容:
$url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['PATH_INFO'];
我也试过了:
$url = "http://".$_SERVER['HTTP_REFERER'].$_SERVER['REQUEST_URI'];,
但都没有用。
我只是在学习 PHP 和脚本,所以我可能犯了一些错误。感谢您的帮助!
【问题讨论】:
-
这看起来不像 PHP 正在做任何交互工作。如何使用 AJAX / JavaScript 获取信息?请发布该代码。你需要在
success事件中做点什么。 -
抱歉,没有正确理解问题。现在我已经回答好了。