如何将电子邮件发送到隐藏输入字段中提供的电子邮件地址?

时间:2013-12-12 16:07:31

标签: php forms email

我有一个简单的PHP电子邮件表单。这将用于多人,所以为了让人们更容易,我的html表单中有一个隐藏的输入字段,基本上是“mailTo”电子邮件地址。

如何通过电子邮件将电子邮件发送到隐藏输入字段中提供的地址?

这是我的HTML:

<div id="formholder">
    <form method="post" action="http://www.artofliz.com/hosting/php/process.php">
        <!-- THE CLIENT'S EMAIL TO ADDRESS GOES HERE!!! -->
        <input name="to" type="hidden" value="lroberts@platinumstrategies.com" />

        <label for="name">Name</label>
        <input name="name" placeholder="Full Name" type="text" />

        <label for="email">Email</label>
        <input name="email" placeholder="youremail@example.com" type="email" />

        <label for="phone">Phone</label>
        <input name="phone" placeholder="XXX-XXX-XXXX" type="tel" />

        <input id="submit" name="submit" type="submit" value="Submit" />
    </form>
</div>

这是我的PHP处理程序:

<?php
    $to = $_POST['to'];
    $name = $_POST['name'];
    $email = $_POST['email'];
    $phone = $_POST['phone'];

    $from = 'From: noreply@platinumstrategies.com';
    // $to = 'lroberts@platinumstrategies.com';
    $subject = 'Free Guide Download';

    $body = "From: $name\n Email: $email\n Phone: $phone";

    if ($_POST['submit']) {
      /* Anything that goes in here is only performed if the form is submitted */
      if (mail ($to, $subject, $body, $from)) {
        echo '<p>Your message has been sent!</p>';
      } else {
        echo '<p>Something went wrong, go back and try again!</p>';
      }
    }
?>

http://pastebin.com/cqZP949r - 此外,我应该注意,注释掉的'to'可以正常工作。这就是我目前正在努力做的事情。

非常感谢你的帮助。

0 个答案:

没有答案