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

时间:2015-10-29 14:35:07

标签: html wordpress

我正在尝试创建一个简单的表单,该表单收集四个信息,通过用户自己的电子邮件发送给供应商,以请求第三方访问其部分数据的权限。

screen shot

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

通过电子邮件向供应商发送电子邮件

请告诉我如何插入文字

非常感谢

1 个答案:

答案 0 :(得分:0)

从这里开始: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,但这不是保证。我还建议你让人们填写任何信息,以便你可以联系他们,如电子邮件或电话。

此处有更多信息:

相关问题