php - 发送电子邮件bu URL参数
问题描述
我的网站上有一个联系表,我想在用户提供联系信息时向我的个人收件箱发送一封电子邮件。但我想创建一个 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>
解决方案
要将GET
参数附加到POST
表单,您可以将它们附加到action
属性中的 URL:
<form action="?subject=<?= urlencode($subject); ?>#" method="POST">
#
片段必须放在参数之后,并且?
参数需要进行 url 编码。
在目标脚本中,您可以使用来自$_GET
超全局的这些变量:
<?php
echo htmlentities($_GET['subject']);
推荐阅读
- c++ - 声明数组并打印 [BUG?]
- tcl - tcl数组中一个键的多个值
- c++ - 堆栈上的数组与堆上的数组上的 sizeof()
- php - 获取两个日期之间不同的天数(不包括周末)
- php - php artisan migrate: with mamp: Access denied for user 'root'@'localhost'
- python - Python:让按键工作的问题
- python - 如何在不退出程序的情况下检查一个数字是否为素数并再次询问用户它是否不是素数?
- jsp - 如何使用 Java EE 显示结果
- clang - clang 中定义的所有内置宏在哪里?
- vue.js - VueJS:Chrome devtools 不会立即更新数组(在父组件中)。为什么?