首页 > 解决方案 > 发送电子邮件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>

标签: phpweb

解决方案


要将GET参数附加到POST表单,您可以将它们附加到action属性中的 URL:

    <form action="?subject=<?= urlencode($subject); ?>#" method="POST">

#片段必须放在参数之后,并且?参数需要进行 url 编码。

在目标脚本中,您可以使用来自$_GET超全局的这些变量:

<?php
echo htmlentities($_GET['subject']);

推荐阅读