我在我的网站上有一个联系表格,我想发送一封电子邮件到我的个人收件箱,当用户提供联系信息。但我想创建一个php文件,我将设置一些参数到这个文件的URL (如名称,电子邮件或消息),我将发送带有参数值的电子邮件。
注意:我知道如何从我的网站主机发送电子邮件,所以我不需要发送电子邮件的帮助。
(很抱歉我的英语不好:-( )
这是我的联系表单代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="css/style.css">
<title>Contact with me</title>
</head>
<body>
<nav>
<div class="logo">
<h3>George Sepetadelis</h3>
</div>
<ul class="nav_links">
<li>
<a class="home"><b>Home</b></a>
</li>
<li>
<a class="project"><b>Projects</b></a>
</li>
<li>
<a class="aboutme"><b>About me</b></a>
</li>
<li>
<a style="color: cadetblue;" class="contact"><b>Contact</b></a>
</li>
</ul>
</nav>
<center>
<h1 class="contact-title">Contact with me</h1>
<br><br>
<div class="form-div">
<form action="#" method="POST">
<h2 style="color:darkcyan; font-family: 'Poppins', sans-serif;"><b>Contact form</b></h2>
<br><br>
<input type="text" name="name" id="name" placeholder="Your full name" autocomplete="off" required>
<br><br>
<input type="email" name="email" id="email" placeholder="Your email" autocomplete="off" required>
<br><br>
<input type="text" name="message" id="message" placeholder="Type here what you want exactly..." required>
<br><br><br>
<p style="font-family: 'Poppins', sans-serif;">Contact reason:</p><br>
<div class="reason-div" style="text-align: left; width: 120px; ">
<input type="radio" id="mobile-app" name="reason" value="mobile app">
<label for="mobile-app">Mobile-app</label><br>
<input type="radio" id="web-app" name="reason" value="web-app">
<label for="web-app">Web-app</label><br>
<input type="radio" id="desktop-app" name="reason" value="desktop-app">
<label for="desktop-app">Desktop-app</label><br>
<input type="radio" id="other" name="reason" value="other">
<label for="other">Other</label>
</div>
<br><br>
<button class="submit-contact-form" type="submit"><b>Send contact form </b></button>
<br><br>
</form>
</div>
</center>
<script src="js/main.js"></script>发布于 2020-12-02 18:23:50
那么,如果我理解你想把页面的输入值发布到php代码中,然后用它做点什么呢?您可以尝试一下,并在末尾的php部分中执行php:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="css/style.css">
<title>Contact with me</title>
</head>
<body>
<nav>
<div class="logo">
<h3>George Sepetadelis</h3>
</div>
<ul class="nav_links">
<li>
<a class="home"><b>Home</b></a>
</li>
<li>
<a class="project"><b>Projects</b></a>
</li>
<li>
<a class="aboutme"><b>About me</b></a>
</li>
<li>
<a style="color: cadetblue;" class="contact"><b>Contact</b></a>
</li>
</ul>
</nav>
<center>
<h1 class="contact-title">Contact with me</h1>
<br><br>
<div class="form-div">
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">
<h2 style="color:darkcyan; font-family: 'Poppins', sans-serif;"><b>Contact
form</b></h2>
<br><br>
<input type="text" name="name" id="name" placeholder="Your full name" autocomplete="off" required>
<br><br>
<input type="email" name="email" id="email" placeholder="Your email" autocomplete="off" required>
<br><br>
<input type="text" name="message" id="message" placeholder="Type here what you want exactly..." required>
<br><br><br>
<p style="font-family: 'Poppins', sans-serif;">Contact reason:</p><br>
<div class="reason-div" style="text-align: left; width: 120px; ">
<input type="radio" id="mobile-app" name="reason" value="mobile app">
<label for="mobile-app">Mobile-app</label><br>
<input type="radio" id="web-app" name="reason" value="web-app">
<label for="web-app">Web-app</label><br>
<input type="radio" id="desktop-app" name="reason" value="desktop-app">
<label for="desktop-app">Desktop-app</label><br>
<input type="radio" id="other" name="reason" value="other">
<label for="other">Other</label>
</div>
<br><br>
<button class="submit-contact-form" type="submit"><b>Send contact form </b>
</button>
<br><br>
</form>
</div>
</center>
<script src="js/main.js"></script>
<?php
//this is the do something place with PHP
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// collect value of input field
$name = $_POST['name']; //you get it by ID.
//here I write the name just to do something with it, but you can do whatever you want and send your email then in the php section
if (empty($name)) {
echo "Name is empty";
} else {
echo $name;
}
}
?>发布于 2020-12-02 18:14:45
要将GET参数附加到POST表单,可以将它们附加到action属性中的URL:
<form action="?subject=<?= urlencode($subject); ?>#" method="POST">#片段必须放在?参数之后,并且参数需要经过url编码。
在目标脚本中,您可以使用来自$_GET超级全局的这些变量:
<?php
echo htmlentities($_GET['subject']);https://stackoverflow.com/questions/65105868
复制相似问题