我有一个非常简单的 PHP 联系表,其中包含电子邮件和消息。我想添加一个功能,以便每次发送联系表单时我都知道发送它的 URL,并且我想将它包含在发送到我的电子邮件的消息正文中。
这是运行联系表单的 PHP 代码。
<?php
$to = "email@email.com" ;
$from = "Something Broke!" ;
$subject = "Something Broke!";
$fields = array();
$fields{"emailOptional"} = "Email:";
$fields{"message"} = "Message:";
$body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%s: %s\n",$b,$_REQUEST[$a]); }
if(mail($to, $subject, $body)){
echo 'sent';// we are sending this text to the ajax request telling it that the mail is sent..
}else{
echo 'failed';// ... or to tell it that it wasn't sent
}
?>
这是标记:
<form method="post" action="widgetScript.php" id="contactForm">
<input type="text" name="emailOptional" placeholder="Your Email (optional)" />
<textarea rows="5" type="text" name="message" id="message"></textarea><br />
<input type="submit" name="send" id="Submit" value="Send">
</form>
我发现如果我理解正确,您可以使用 [_post_url] 获取当前 URL - 但我不确定如何处理它。将不胜感激我能得到的所有帮助