Wordpress:在 mailto 正文中添加输入框值

Wordpress: add input box values in mailto body text

我正在尝试创建一个简单的表格,它收集四项信息,通过用户自己的电子邮件发送给供应商,以请求允许第三方访问他们的某些数据。

screen shot

你的名字:
农场供应编号 1:
农场供应编号 2:
农场供应编号 3:

在这里给你的供应商发电子邮件

能否请您告诉我如何插入文本

非常感谢

如果从这里开始:I am looking to collect data from input boxes and then use this text in the body of the email. Thank you. 我为您写了以下内容:

<?php
    if(isset($_POST['submit'])) { 
        $name = $_POST['name'];
        $supplier1 = $_POST['supplier1'];
        $supplier2 = $_POST['supplier2'];
        $supplier3 = $_POST['supplier3'];

        $to = "your_email@gmail.com"; // example, fill in your own
        $subject = "Mail sent from the form on the website by ".$name;
        $message = $name." has sent in the following suppliers:\r\nSupplier 1: ".$supplier1."\r\nSupplier 2: ".$supplier2."\r\nSupplier 3:".$supplier3;

        mail($to, $subject, $message);
        echo "E-mail has been sent."
    }
?>

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <label for="name">Your name : </label><input type="text" name="name" required><br>
    <label for="supplier1">Farm supply number 1 : </label><input type="number" name="supplier1" required><br>
    <label for="supplier2">Farm supply number 2 : </label><input type="number" name="supplier2" required><br>
    <label for="supplier3">Farm supply number 3 : </label><input type="number" name="supplier3" required><br>
    <input type="submit" name="submit" value="Click here to send e-mail"
</form>

如果有任何问题,请告诉我,我没有对此进行测试。

如果您想增加安全性,请使用 htmlentities() 函数之类的东西。

你会得到像

这样的东西

<form method="post" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>">

$supplier1 = htmlentities($_POST['supplier1']);

您还可以在发送前检查字段是否实际填写时增加一些额外的安全性,我在 html 上使用了 required,但这并不能保证。我还建议您让人们填写任何信息,以便您可以联系他们,例如电子邮件或 phone.

在此处获取更多信息: